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



Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


kote
java button
1 Answer(s)      5 years and 6 months ago
Posted in : Java Beginners



Advertisement
View Answers

July 24, 2009 at 11:10 AM


Hi Friend,

Try the following code:

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

public class CheckBoxForm extends JApplet {
JTextArea t = new JTextArea(6, 15);
private JCheckBox cb1 = new JCheckBox("Check Box 1");
private JCheckBox cb2 = new JCheckBox("Check Box 2");
private JCheckBox cb3 = new JCheckBox("Check Box 3");
private JCheckBox cb4 = new JCheckBox("Check Box 4");
private JButton button=new JButton("Submit");
public void init() {
cb1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
trace("1", cb1);
}
});
cb2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
trace("2", cb2);
}
});
cb3.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
trace("3", cb3);
}
});
cb4.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
trace("3", cb4);
}
});
Container cp = getContentPane();
cp.setLayout(new FlowLayout());
cp.add(cb1);
cp.add(cb2);
cp.add(cb3);
cp.add(cb4);
cp.add(button);
button.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
JFrame f=new JFrame();
f.add(new JScrollPane(t));
f.setVisible(true);
f.setSize(300,150);
}
});
}

private void trace(String b, JCheckBox cb) {
if (cb.isSelected())
t.append("Checkbox " + b + " is Selected\n");
}

public static void main(String[] args) {
run(new CheckBoxForm(), 150, 200);
}

public static void run(JApplet applet, int width, int height) {
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(applet);
frame.setSize(width, height);
applet.init();
applet.start();
frame.setVisible(true);
}
}

Hope that it will be helpful for you.
Thanks


Related Tutorials/Questions & Answers:
button in java
button in java  how can i compare names of two buttons after...) { System.out.println("button clicked"); } } Thanks   Hi.... i want to keep the labels on the button same yet identify them individually
java button - Java Beginners
java button  i want to make form with checkboxes, after this i need 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
Advertisements
java radio button and exception
java radio button and exception  Dear Sir/Madam, I have problem with my addBagelRadioButton and addCheeseRadioButton. There should be only 1 radio button can be selected, but somehow 2 can be selected the same time. Also, I
button with rounded corner in java
button with rounded corner in java  Hi, I want to create a JButton with rounded corners in swings. I went through many programs but did not got the solutions. Thanks and regards, Vivek Birdi
JRadio Button - Java Beginners
JFrame("Frame in Java Swing"); f.getContentPane().setLayout(null); JLabel lbl1
java swing button click event
java swing button click event  java swing button click event   public void doClick()   Java Swing Tutorials
creating browse button - Java Beginners
creating browse button  how can we create a browse button along with a textfield in java swings
creating browse button - Java Beginners
creating browse button  how can we create a browse button along with a textfield in java swings
creating browse button - Java Beginners
creating browse button  how can we create a browse button along with a textfield in java swings
creating browse button - Java Beginners
creating browse button  how can we create a browse button along with a textfield in java swings
creating browse button - Java Beginners
creating browse button  how can we create a browse button along with a textfield in java swings
creating browse button - Java Beginners
creating browse button  how can we create a browse button along with a textfield in java swings
creating browse button - Java Beginners
creating browse button  how can we create a browse button along with a textfield in java swings
creating browse button - Java Beginners
creating browse button  how can we create a browse button along with a textfield in java swings
creating browse button - Java Beginners
creating browse button  how can we create a browse button along with a textfield in java swings
creating browse button - Java Beginners
creating browse button  how can we create a browse button along with a textfield in java swings
creating browse button - Java Beginners
creating browse button  how can we create a browse button along with a textfield in java swings
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
creating browse button - Java Beginners
creating browse button  how can we create a browse button along with a textfield in java swings.  Hi friend, import... ActionListener { JButton button; JTextField field; public BrowsePath
Button
Button  How to use image for button in JSF
back button issue - Java Beginners
back button issue  Hello, I have a site that asks for user and password to connect it. When the user pushs de LogOut button and later another user pushs the back button of the explorator he can entry in the page of first user
How to call java method on Button click in jsp?
How to call java method on Button click in jsp?  How to call java method on Button click in jsp
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
disable back button - Java Beginners
disable back button  I wanted the code for disabling back button in my application(The scenario is like when im in my register user page and try... displayed but..when i click back button i go back to the register page which should
Setting icon on the button in Java
Setting icon on the button in Java   ... on the button in Java Swing. This program sets the icon on the button in Java...(Icon): Above method sets the specified Icon on the button. ImagIcon(String image
Draw a line in a JPanel with button click in Java
Draw a line in a JPanel with button click in Java  Draw a line in a JPanel with button click in Java
Server running Button - Java Beginners
. The problem is with the display , when I run the GUI and click on the play button
How to Hide Button using Java Swing
How to Hide Button using Java Swing  Hi, I just begin to learn java programming. How to hide the button in Java programming. Please anyone suggest or provide online example reference. Regards,   hi, In java
Java Applet - Adding a Button to Decrease a Total
Java Applet - Adding a Button to Decrease a Total  Hello everyone... { public int testone = 0; public void init() { Button one = new Button..., it will display a button in a frame, that when clicked on will increase a total. Basically
Open website on Button Click - Java Beginners
Open website on Button Click  Hello sir I want to open website on button click using java swing plz help me sir. in my swing application one "VISIT US BUTTON" i want to open my website on Button CLick  Hi Friend
 

 

 

DMCA.com