Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Swing-AWT add button to the frame
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


chitra
add button to the frame
1 Answer(s)      6 years and a month ago
Posted in : Swing AWT



Advertisement
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... program has used simply the Button class for creating a command button on the frame
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 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 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
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
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.*"%>
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
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
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
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
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
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
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   
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
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
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
frame update another frame.
frame update another frame.   How do I make a link or form in one frame update another frame
add
How to add two numbers in Java  add two number   Here is a java example that accepts two integer from the user and find their sum. import java.util.*; class AddNumbers { public static void main(String[] args
add
add two no in Java  Java Add Example that accepts two integer from the user and find their sum  Here is a java example that accepts two integer from the user and find their sum. import java.util.*; class AddNumbers
add
How to add two int numbers in Java Example  How to add two int numbers in Java Example  Here is a java example that accepts two integer from the user and find their sum. import java.util.*; class AddNumbers
add
Java Example to add two numbers  Java Example to add two numbers  Here is a java example that accepts two integer from the user and find their sum. import java.util.*; class AddNumbers { public static void main
add
Java Program to add two numbers  Java Program to add two numbers  Here is a java example that accepts two integer from the user and find their sum. import java.util.*; class AddNumbers { public static void main
Button
Button  How to use image for button in JSF
struts2 how can we add an radio button to form using a class(doa)
struts2 how can we add an radio button to form using a class(doa)  Hi I had created an class of subscription,and iam trying to add an radio button on the registration form how to do plz help me out here is my code model
struts2 how can we add an radio button to form using a class(doa)
struts2 how can we add an radio button to form using a class(doa)  Hi I had created an class of subscription,and iam trying to add an radio button on the registration form how to do plz help me out here is my code model
 

 

 

DMCA.com