Home Answers Viewqa Swing-AWT add button to the frame

 
 


chitra
add button to the frame
1 Answer(s)      4 years and 8 months ago
Posted in : Swing AWT

View Answers

September 30, 2008 at 12:29 PM


Hi chitra,


Plz implement this code.


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

public class ButtonDemo extends JFrame implements ActionListener {
JButton button = new JButton("Button");
JCheckBox myCheckBox = new JCheckBox("Check");
JTextArea text = new JTextArea("Welcome to roseindia");
JPanel bottomPanel = new JPanel();
JPanel pane = new JPanel();


public ButtonDemo() {
bottomPanel.setLayout(new FlowLayout());
bottomPanel.add(myCheckBox);
bottomPanel.add(button);

pane.setLayout(new BorderLayout());
pane.add(bottomPanel, BorderLayout.SOUTH);
pane.add(text, BorderLayout.CENTER);

getContentPane().add(pane, BorderLayout.CENTER);

button.addActionListener(this);
myCheckBox.addActionListener(this);
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
}

public static void main(String[] args) {
ButtonDemo bdemo = new ButtonDemo();
bdemo.setLocation(10, 10);
bdemo.setSize(300, 300);
bdemo.setVisible(true);
}

public void actionPerformed(ActionEvent e) {
if (e.getSource() == button)
text.setText("A button click");
else if (e.getSource() == myCheckBox)
text.setText("The checkbox state changed to " + myCheckBox.isSelected());
else
text.setText("E ...?");
}
}

--------------------------------------------

Visit for more information.

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

Thanks.

Amardeep









Related Pages:
add button to the frame - Swing AWT
add button to the frame  i want to add button at the bottom... table with database data JFrame frame = new JFrame("View Patients...); JScrollPane scrollPane = new JScrollPane(table); frame.getContentPane().add
how to add panel inside frame?
how to add panel inside frame?  I prepared a Frame with two labels and text fields and one button.when ever user clicks on the button two text fields... to add panel after those components.but while compilation its showing errors.how
call frame - Java Beginners
call frame   dear java, I want to ask something about call frame to another frame and back to first frame. I have FrameA and FrameB. In frameA have a JTextfield1 and Button for browse, and in FrameB have a JTextfield1
Helps with combo box and frame
on add button another frame pop up with text field(name ,address etc..) ,confirm button and cancel button at bottom of the frame. When i put something...(){ JFrame frame = new JFrame("Add-Remove item to list"); String items
How to add icons on a button or any component in java - Java Beginners
How to add icons on a button or any component in java  How to add icons on a button or any component in java?  Hi, import... main(String[] args){ JFrame frame = new JFrame("Icon on button
Frame related query - Java Beginners
{ Button b1; TestFrame() { b1=new Button("hi"); add(b1...) { try{ Frame f1=new Frame(); TextField t=new TextField(10); add(t...Frame related query  hi..... i m having a query dat...can i open
how to go from one frame to another frame in swings - Java Beginners
how to go from one frame to another frame in swings  Hi, My task is to go from one frame to another.......... let us think that iam having two buttons on a frame........button names are ok and next........ when iam clicking
How to Create Button on Frame
How to Create Button on Frame     ... a command button on the Java Awt Frame. There is a program for the best... program has used simply the Button class for creating a command button on the frame
adding of two numbers in designing of frame
create two textfield for mark1&mark2 from db.how to add these two numbers...); final JTextField text3=new JTextField(20); JButton button=new JButton...(text3); p.add(button); f.add(p); f.setVisible(true
frame generation
frame generation  Hi I wnat to genarate one frame with two tabs... on the tab selection I want to clikc the radio button..when i ckick the radio button i want list of items in agrid format in ascrollpane.. like **working
Help me to write this simple java frame program
Help me to write this simple java frame program   I want to write a Java program for.... To create a frame with 4 text fields;name,street,city and pin;with suitable labels. Also add a button "OK". After enter values
Setting the close button operation for the frame in Java
Setting the close button operation for the frame in Java... will learn how to implement the close button of any frame or window in java application. By default the close button of the frame is not in working state. If you
Image on Frame in Java AWT
to add the image on the frame using the addImage() method of the MediaTracker class... button of the frame. MediaTracker :  MediaTracker is the class... Image on Frame in Java AWT     
How to close a frame on action event of a button from a different class ?
How to close a frame on action event of a button from a different class ?  How to close a frame on action event of a button from a different class ? I have a designed a control-frame on 1 class which has jbutton components, I
how to call a frame having threading concept
how to call a frame having threading concept   i hav a frame having buttton on it .on click event of the button ,i want to call another frame which... of that frame ,frame is displaying but no other content. that frame contains
link to other frame - Applet
link to other frame  how a button to open to another frame? and the frame can keyin the data and it can show at the previous frame
How will you add panel to a frame? - Java Interview Questions
How will you add panel to a frame?   How will you add panel to a frame?   you can simply use add method to add panel to a frame i.e panelA.add(frameA)  Hi Friend, Using add() method of JFrame. import
how to convert java Applet to Jave Frame
); text.setBounds(200,80,100,20); add(text); b1 = new Button... to convert Java Applet to Jave Frame below this code is my applet source code... label1,label2,label3,label4,label5,label6,label7,label8,label9; Label lab; Button b1,b2; JComboBox combo
Creating a Frame
; Setting the Icon for a Frame    Showing a Dialog Box  ... an Icon to a JButton Component    Making a Frame Non-Resizable    Removing the Title Bar of a Frame   
Remove Minimize and Maximize Button of Frame in Java
Remove Minimize and Maximize Button of Frame in Java..., the frame or window displays on the screen without minimize and maximize button... the coding methods to remove the minimize and maximize button from the title bar
java button - Java Beginners
button thich will open new pop-up page, where will be shown only this checkboxes..."); private JCheckBox cb4 = new JCheckBox("Check Box 4"); private JButton button...); cp.add(cb2); cp.add(cb3); cp.add(cb4); cp.add(button
Dialog Frame focus - Framework
visit the parent frame also. But on some event(like a button), I want my dialog frame to be focussed/active.(Here i dont want to reopen it. As it is already opened...Dialog Frame focus  Is it possible somehow to focus/activate/select
how to add a update button in the following jsp
how to add a update button in the following jsp  Once the excel from the following jsp is loaded to the broswer, how to add a button in the jsp to allow the user to update the excel? thanks, <%@page import="java.io.*"%>
swing frame problem
a frame which have few buttons and Text Box to get some data from user at this time when I will click on submit button then next frame should be open with in same...swing frame problem  Hi All, I m creating a swing/awt based window
Making a Frame Non Resizable in Java
Making a Frame Non Resizable in Java       This program illustrates you how to make a frame non resizable. It means, disabling the maximize button of the frame. The setResizable
Making a Frame Non Resizable in Java
a frame non resizable. It means that the disabling the maximize button of the frame. The setResizable() method has been used to make the frame resizable... Making a Frame Non Resizable in Java   
switch CAPSLOCK button in my progranm...
switch CAPSLOCK button in my progranm...  I found that function which does the Capslocks job,when am running my program if the capslock button... the capslocks switch button to become a button that i can switch it between on and off
how to add save,discard,& cancel button in a message box - Struts
how to add save,discard,& cancel button in a message box  how to add save,discard,& cancel button in a message box
Creating a Frame
the boolean value true. The close button of the frame by default performs the hide... Creating a Frame : Swing Tutorials       This program shows you how to create a frame in Java Swing
FRAME
FRAME  WHILE I'M RUNNINGFILE OF A GUI PROGRAMME(JDBC CONNECTION) INSTEAD OF OUTPUT FRAME ONLY TWO BLANK FRAMES ARE GETTING DISPLAYD... CAN ANYONE HELP ME TO SOLVE DS PROBLEM
FRAME
FRAME  WHILE I'M RUNNINGFILE OF A GUI PROGRAMME(JDBC CONNECTION) INSTEAD OF OUTPUT FRAME ONLY TWO BLANK FRAMES ARE GETTING DISPLAYD... CAN ANYONE HELP ME TO SOLVE DS PROBLEM
NoughtsAndCrossesGame play button doesn't work
NoughtsAndCrossesGame play button doesn't work   /* * To change...() { //** //* The button panel //*/ } class NoughtsAndCrossesButtonPanel...); // Create the buttons and add them to the JFrame for (int i = 0; i < 9; i
NoughtsAndCrossesGame play button doesn't work
NoughtsAndCrossesGame play button doesn't work   /* * To change...() { //** //* The button panel //*/ } class NoughtsAndCrossesButtonPanel...); // Create the buttons and add them to the JFrame for (int i = 0; i < 9; i
frame
frame  how to creat a frame in java   Hi Friend, Try the following code: import java.awt.*; import javax.swing.*; import java.awt.event.*; class RetrieveDataFromTextFields{ public static void main(String[] args
Show Addition, Subtraction, Intersection, Exclusive OR on one Frame
Frame       This section... frame.  In this section, we are providing you an example which performs all the functions on one frame. Two classes Rectangle2D and Ellipse2D are used
Show Addition, Subtraction, Intersection, Exclusive OR on one frame
Show Addition, Subtraction, Intersection, Exclusive OR on one frame... illustrates you how to show Addition, Subtraction, Intersection, ExclusiveOR on one frame... the functions on one frame. Two classes Rectangle2D and Ellipse2D are used which
Add a fram
Add a fram  I want to put an image on frame on my GUI(Net Beans).please tell me the way to put this. only for frame.. thanks and regards, Rahul...) { JFrame frame = new JFrame(); JPanel p=new DisplayImage(); frame.add(p); frame.setSize
JFrame Close On Button Click
to close frame on click on the button. This example explains you how a frame can... on the button on a frame. In this example we will use the dispose() method to close... in Java and close this frame by clicking on a button . In this example we
Java program to create a frame with 4 fields;name,sreet,city,pin;with suitable table
Java program to create a frame with 4 fields;name,sreet,city,pin;with suitable table  Java program to create a frame with 4 fields;name,street,city,pin;with suitable table. Also add a button "OK". whe it is clicked
is it possible to add a button inside an autocomplete jquery ui plugin?
is it possible to add a button inside an autocomplete jquery ui plugin?  is it possible to add a button inside an autocomplete jquery ui plugin? My... a button that will open a jquery modal form, that the user can enter the desired data
Create Round Button in Java swing
(); frame.getContentPane().add(button); frame.getContentPane...Create Round Button in Java swing In this tutorial, we are going to create a button of round shape. Java2D APIs and Java Swing make it easy to implement
Java Button issue - Java Beginners
Java Button issue  I have this project and I have numerous steps to it. I am trying to figure out what I have to do to make my frame panel do what... is clicking the round or oval button and than perform the proper mathmathical
Frame refresh problem - Swing AWT
Frame refresh problem  Whenever I close a child frame and reload it using the button on parent frame controls on the child frame load twice...[] args){ JFrame frame=new JFrame(); JButton b=new JButton("Submit"); frame.add(b
How to add
How to add   Hi, I want to make a website which will recommend users books according to the genre selected by them. I am using PHP, JavaScript... to be viewed after clicking a link/button/whatever mentioning -"Next 10
How to add a columns with a button set to a Jtable built with database result set
How to add a columns with a button set to a Jtable built with database result..., there should be another button to get further details of a account such as transactions... that button column to the table which is built with database result set. i would thank
Create a Frame in Java
string argument which is the title of the window or frame. Then you can add user... to the frame. Method add() adds a component to it's container. setSize (width... Create a Frame in Java     
Removing the Title Bar of a Frame
button, maximize button and close button with the title of the frame... Removing the Title Bar of a Frame   ... bar of a frame or window in java. That means show the frame or window without
Java App - Add, Delete, Reorder elements of the buttons
Java App - Add, Delete, Reorder elements of the buttons  Hello... on "Element N" Button. He can too delete an element or change the order... to add each panel after each one .. Thats why I created a new JPanel which
To write a Java program To create a frame with 4 fields;name,street,city,pin;with suitable table
a frame with 4 fields;name,street,city,pin;with suitable table. Also add a button "OK". when it is clicked, corresponding values...To write a Java program To create a frame with 4 fields;name,street,city,pin

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.