add button to the frame

add button to the frame

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 Tutorials/Questions & Answers:
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
Advertisements
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... button on the frame object. FlowLayout(): This is the constructor of FlowLayout class
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
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 access the object of one frame on clicking a button without using this keyword
how to access the object of one frame on clicking a button without using... extends Frame { public static void main(String args[]) { Button b1... Button("Yellow"); mb.add(b1); mb.add(b2); mb.add(b3
uinavigationcontroller add right button
uinavigationcontroller add right button  Hi, How to add the right button programatically to a UINavigation Controller? Thanks   Hi, You can use the following code: - (void)viewDidLoad { [super viewDidLoad
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
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
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
frame
frame  how to creat a frame in java   Hi Friend, Try the following code:ADS_TO_REPLACE_1 import java.awt.*; import javax.swing.*; import java.awt.event.*; class RetrieveDataFromTextFields{ public static void
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
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.*"%>
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
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
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   
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... to create a frame in Java and close this frame by clicking on a button
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
frame update another frame.
frame update another frame.   How do I make a link or form in one frame update another frame
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 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
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
How to add radio button value in a table for particular field?
How to add radio button value in a table for particular field?  Hi,I... dynamically from other table and two radio button one for present and the second... one radio button for text field then it insert only one value absent OR present
Button
Button  How to use image for button in JSF
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
one frame update another frame
one frame update another frame  How do I make a link or form in one frame update another frame
Drag and Drop components from one frame to another frame
button etc.) from one frame to another frame. In this code we have used... Drag and Drop components from one frame to another frame...) { Button button = new Button("Drag this button"
panel and frame
panel and frame  What is the difference between panel and frame
Java Frame
Java Frame  What is the difference between a Window and a Frame
how to add components (like button , checkbox etc) in a table column in core java
how to add components (like button , checkbox etc) in a table column in core java  plz tell me how to add components(like button, checkbox, radiobutton etc)in a table column in core java
button
button  can i give multiple commands on click of a button? if yes how can i do that?? multiple commands can we retriving dat from database, capturing data, moving to next page.. etc
button
button  can i give multiple commands on click of a button? if yes how can i do that?? multiple commands can be retriving dat from database, capturing data, moving to next page.. etc
how can i add wirecard option(or button ) at my web page plz tell all steps? View Answers
how can i add wirecard option(or button ) at my web page plz tell all steps? View Answers  how can i add wirecard option(or button ) at my web page plz tell all steps? View Answers
billing frame
billing frame  how to generate billing frame using swing which contain sr. no, name of product, quantity, price & total
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
Image on frame
Image on frame   Hi, This is my code. In this I am unable to load... java.awt.event.*; public class AwtImg extends Frame { Image img; public...(); } AwtImg() { super("Image Frame"); MediaTracker mt=new
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
Frame query
Frame query  Hi, I am working on Images in java. I have two JFrame displaying same image. We shall call it outerFrame and innerFrame.In innerFrame i am rotating the image.After all the rotations i need to display this image
Frame
frame
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
Radio Button In Java
Radio Button In Java       Introduction In this section, you will learn how to create Radio Button on the frame. The java AWT , top-level window, are represent by the CheckBoxGroup
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
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   
how can i close a frame. - Java Beginners
and in that table is displayed and one button is added to that frame............my target is when i click on that button, a new frame is coming and updated table...how can i close a frame.  Hi, My question is how can we close
how to create frame in swings
how to create frame in swings  how to create frame in swings
collection frame work
collection frame work  explain all the concept in collection frame work
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
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

Ads