Home Answers Viewqa Java-Beginners How can I Define a JFrame subclass that has four vertically positioned buttons.

 
 


charlotte
How can I Define a JFrame subclass that has four vertically positioned buttons.
1 Answer(s)      3 years and 2 months ago
Posted in : Java Beginners

How can I Define a JFrame subclass that has four vertically positioned buttons. The labels for the four buttons are Senior, Junior, Sophomore, and Freshman. When a button is clicked, display a message that identifies which button is clicked, using JOptionPane.
View Answers

March 22, 2010 at 12:08 PM


Hi Friend,

Try the following code:

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;

public class DisplayButtons extends JFrame {
int i=0;
static JPanel panel;
public DisplayButtons(){
JButton[] buttons = new JButton[4];
panel=new JPanel(new GridLayout(4,1));
String b[]={"Senior","Junior","Sophomore","Freshman"};
for(i = 0; i < buttons.length; i++) {
buttons[i] = new JButton(b[i]);
buttons[i].setSize(80, 80);
buttons[i].setActionCommand(b[i]);
buttons[i].addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e) {
String choice = e.getActionCommand();
JOptionPane.showMessageDialog(null, "You have clicked: "+choice);
}
});
panel.add(buttons[i]);
}
}
public static void main(String[]args){
DisplayButtons frame=new DisplayButtons();
frame.add(panel);
frame.pack();
frame.setVisible(true);
}
}

For more information, visit the following link:

http://www.roseindia.net/java/example/java/swing/create_multiple_buttons_using_ja.shtml

Thanks









Related Pages:
How can I Define a JFrame subclass that has four vertically positioned buttons. - Java Beginners
How can I Define a JFrame subclass that has four vertically positioned buttons.  How can I Define a JFrame subclass that has four vertically positioned buttons. The labels for the four buttons are Senior, Junior, Sophomore
Tiny Window with subclass
). This means it can do everything a JFrame can, in addition to what we define... by defining a subclass of JFrame. All the work of buiding the JFrame will be put... program and one containing the JFrame subclass. It's perhaps more common
JFrame
Jframe. How can i do it. Please help me to do it. Or what else can i have...JFrame  Hi, I have JFrames in my application and i'm developing application using NetBeans IDE 6.5. I have many jframes. Whenver i click a menu
Vertically center page
Vertically center page  I know how to center the text of the page Horizontally ..but is it possible to vertically center page in HTML or CSS?   You can set the Height, width and left, right alignment for the text in CSS
How can combine threads and buttons?
How can combine threads and buttons?  I would like to start an application, stop it and restart it again and stop etc. I tried the following code. It does start and stop, but I get an error when I try to restart. Any
Second Window
a subclass of JFrame (a window) that constructs a JPanel to put the one component... a subclass of JFrame //Note 1 * @version 2004-10-25 * @author Michael Maus... (the Java class for a window), which means that it can do everything a JFrame can
how to add scrollbar to JFrame
how to add scrollbar to JFrame  hello friends i am making a java application in which i have a frame to which i wanted to add scrollbars but when i add my panel to scrollpane and then add that scrollpane to JFrame than
how to add scrollbar to JFrame
how to add scrollbar to JFrame  hello friends i am making a java application in which i have a frame to which i wanted to add scrollbars but when i add my panel to scrollpane and then add that scrollpane to JFrame than
how to add scrollbar to JFrame
how to add scrollbar to JFrame  hello friends i am making a java application in which i have a frame to which i wanted to add scrollbars but when i add my panel to scrollpane and then add that scrollpane to JFrame than
how to add scrollbar to JFrame
how to add scrollbar to JFrame  hello friends i am making a java application in which i have a frame to which i wanted to add scrollbars but when i add my panel to scrollpane and then add that scrollpane to JFrame than
how to add scrollbar to JFrame
how to add scrollbar to JFrame  hello friends i am making a java application in which i have a frame to which i wanted to add scrollbars but when i add my panel to scrollpane and then add that scrollpane to JFrame than
how to display a table and buttons in swings - Java Beginners
how to display a table and buttons in swings  Hi frends, Actually i want to display a table during runtime and at the same time i also want to add different buttons below this displayed table using swings.....please can any
JFrame - Window
. Subclass JFrame, build in constructor. Another better way is to define... pane or menu bar. Constructors You can create a frame like this: JFrame w... Java: JFrame - Window Description The javax.swing.JFrame class is used
how can i define only one method from the interface. - Java Beginners
how can i define only one method from the interface.  If i am having an interface with 3 methods(declaration) . If i want to use only one method... the solution for that. please i want it immediately.  Hi friend
HTML custom buttons
HTML custom buttons  How can I make a form with custom buttons
buttons in netbeans,java
buttons in netbeans,java  respected sir, i would like to known how...{ ButtonExample(){ JFrame f=new JFrame(); JButton b=new JButton("Click...(){ public void actionPerformed(ActionEvent e){ JFrame frame=new JFrame
jframe
jframe  how to create a jframe.provide me the java code pls
java buttons - Swing AWT
be disappear.how can i code this?  Hi Friend, Try the following code...java buttons  There are 3 buttons in a window....A,B,C.If a user...*; public class HideButton { public static void main(String[] args) { JFrame f
How to create file from input values in Jframe ?
How to create file from input values in Jframe ?  hi i m doing my... to achieve this in jframe ? can you please post me the code for it ? Thank you, waiting... an object for it.my java code is public class submit { JFrame frame; JTextArea
JFrame Components Printing - Swing AWT
JFrame Components Printing  hi sir i am doing a project so i am working in netbeans i have to print a JFrame it contains Labels and few textboxfields so i want to take the whole JFrame contents for printing so would you
Buttons
Buttons  I have created a web page with radio button group with two radio buttons for accepting the home appliances categories,Kitchen appliances... radio button is selected.Which event listener do I need to implement for this task
define a constant.
define a constant.  How do you define a constant?   Hi, With the help of define() directive, you can create constant in php. And here is how: <?php define('NAME', 'Bharat'); ?> Thanks
how to display a table and buttons in swings - Java Beginners
how to display a table and buttons in swings  Hi frends, Actually i want to display a table during runtime and at the same time i also want to add different buttons below this displayed table using swings.....please can any
How can I paginate a table which has shown in a div through Ajax in client side without using database
How can I paginate a table which has shown in a div through Ajax in client side without using database   The table is shown by calculation in a PHP script file so The data not store any where so please give me the way to paginate
space between buttons iPhone SDK
space between buttons iPhone SDK  Hi, can any one please explain how to add space between UIButtons in iPhone SDK. Actually i am creating Multiple... are placed over each other. Please tell me how can i set fix margin between
Radio Buttons in Jsp - JSP-Servlet
Radio Buttons in Jsp  Hi, i have a page in which there are lot of radio buttons [IMG]http://i38.tinypic.com/jzi6vc.jpg[/IMG] see the above picture..." depending on the value in the String radio button has to be checked. How to do
how can i display a editable result of form?
how can i display a editable result of form?  how can i display a editable result of form? i know how to display form result but the result... show the result but i can not modify the result. how can i display modifyable
Tab sequence problem with Radio buttons - JSP-Servlet
from 1 year radiobutton to courier button but tab sequence has to go as from 1 year to 2 year to 4 year to courier.... how can I do that in jsp page...could...Tab sequence problem with Radio buttons  Hi, I have membership
How to access Subclass?
How to access Subclass?  How to access subclass in java? please tell me the syntex with an example
how to use a JInternalFrame in a JFrame to create a chat window in a client/server app?
how to use a JInternalFrame in a JFrame to create a chat window in a client/server app?  how to use a JInternalFrame within a JFrame? i want... with JDeskTopPane but i want a chat window which can be moved within the app(just like
passing data from one jframe to another
passing data from one jframe to another  I have two JFrame,built... in the first Jframe to another JLabel in the other JFrame.Can you please help me,how can i do so?PLease,i made lots of search but yet i can't do it...   Hi
how to create directed line between two buttons when i clicked there
how to create directed line between two buttons when i clicked there  Hi I have to create a topology between 6 nodes. 6 nodes are created as 6 buttons and when i clicked in first button and then on second button a directed
Java Spring Desktop application with multiple classes and jframe
i am developing a desktop java spring application..It has many Jframes forms and classes...How to close one Jframe from another..Please tell... First jframe...;This is not disposing Jframe2** t.dispo(); } Second Jframe package
define a constant in php
define a constant in php   hii, How do you define a constant in php?   hello, we can define a constant in php like this define ("CONST", 50
How can i draw a line using java swings
How can i draw a line using java swings  Sir my program contains different components i am using JFrame. I want to draw a straight line between components(Jtextfeilds, Jlabels).So could you help me for it. Thank You
How can i draw a line using java swings
How can i draw a line using java swings  Sir my program contains different components i am using JFrame. I want to draw a straight line between components(Jtextfeilds, Jlabels).So could you help me for it. Thank You
how can i close particular frame in swings - Java Beginners
how can i close particular frame in swings  Hi, I want to know, how can we close a particular frame when mulitple frames are appearing as output... in swings and three frames are having their own close buttons and when i click
URL CODE OF BUTTONS
URL CODE OF BUTTONS   how to create a button tag, i need a details for creating a button tag with url code
Buttons with Icons
Java: Buttons with Icons You can create buttons that show text, icons (images), or both.   In this example you will learn how to create Buttons with Icons on it.   Different images can be associated with different button
labels,textfields,buttons
labels,textfields,buttons  how to set the labels,textfields,buttons at certain positions such that we can add them without layout managers? my program is to design a login page with image and these labels at exact positions
JFrame Button click to start play
JFrame Button click to start play  i made a game and and i add a button in new jframe and i want when i click it it start to play...can anyone help me
How can I do it? .click();
How can I do it? .click();  I have a very unusual problem. I want...("a"); x.click(); </script> So it's click on an element witch one Id's is "a", but I want that it make mouseup in this element. How can I do it, because if I write
Java App - Add, Delete, Reorder elements of the buttons
, I'm developing a Java application. I created this interface with MockupScreens... elements as he needs. He can edit element infomrations at any time by clicking on "Element N" Button. He can too delete an element or change the order
how can i draw a table using applet or swings - Java Beginners
how can i draw a table using applet or swings  Hi RoseIndia, Actually, I was trying for creating a table using applet or swings.......... My task is create a table and enter the integer values during run time......I have
how should i can solve
how should i can solve  Web based program - Input - Person's contact details with Passport Number as Unique Key. Save data in to oracle / MySQL. Output - List of Persons saved in the database. Technology to be used - JSP
objective c define float
objective c define float  Hi, How to define float variable in objective c? Thanks   Hi, Here is the example of defining float variable. float i; i=10; Thanks   Hi, Here is another example: // File
creating dynamic buttons in iphone
creating dynamic buttons in iphone  i Have a UIView and i wanted to create a multiple buttons to that should come on view load. It will be great if that can be removed after sometime or required time.   -(void
This series of progressive examples shows a typical pattern for building simple applications with a window.
, and buttons. It's a simple application that converts strings to uppercase, but can... Window shows a main program that creates an empty window (JFrame). Example - Second Window shows a main program with a subclass of JPanel to build
more Submit buttons in the same form
more Submit buttons in the same form  Can I have two or more Submit buttons in the same form
how can i calculate loan - Java Interview Questions
how can i calculate loan  negotiating a consumer loan is not always straightforward.one form of loan is the discount installment loan, which works as follows. suppose a loan has a face value of 1,000 by 0.15 to yield 225

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.