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



Home Answers Viewqa Java-Beginners Java Button issue
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Anna
Java Button issue
1 Answer(s)      4 years and 4 months ago
Posted in : Java Beginners


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 it is I am assigning it to do. I need the program to be able to tell when the user is clicking the round or oval button and than perform the proper mathmathical problem to give me the volume. I then want the volume to be placed on the same panel....Please HELP!!!!
if (rbutton)is selected than the problem will be double volume = ((length * width) * depth);else(rbutton1)than the problem will be double volume = ((length/2)^2) * depth);

I will copy just that part of the code and hope you guys can help me!!! the code works it shows everything...it just doesnt do the function!

JLabel l2 = new JLabel("Hot Tube");
JPanel p2 = new JPanel();
JLabel label7,label8,lable9;
final JTextField text7,text8,text9;
label7 = new JLabel();
label7.setText("Height:");
p2.add(label7);
text7 = new JTextField(20);
p2.add(text7);
JLabel space6 = new JLabel(" ");
p2.add(space6);
label8 = new JLabel();
label8.setText("Width:");
p2.add(label8);
text8 = new JTextField(20);
p2.add(text8);
JLabel space7 = new JLabel(" ");
p2.add(space7);
lable9 = new JLabel();
lable9.setText("Depth:");
p2.add(lable9);
text9 = new JTextField(20);
p2.add(text9);
JLabel space8 = new JLabel(" ");
p2.add(space8);
JRadioButton rbutton = new JRadioButton("Oval");
p2.add(rbutton);
JRadioButton rbutton1 = new JRadioButton ("Round");
p2.add(rbutton1);
JButton button2 = new JButton("Enter");
p2.add(button2);

tab.addTab( "Hot Tube", null, p2, " Hot Tube" );

Advertisement
View Answers

August 20, 2010 at 12:08 PM


Hi Friend,

You can use the following code:

import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
class JButtonExample extends JFrame implements ActionListener {
JTextField t1,t2,t3;
JButtonExample (){
t1=new JTextField(20);
t2=new JTextField(20);
t3=new JTextField(20);
JLabel l1=new JLabel("Length: ");
JLabel l2=new JLabel("Width: ");
JLabel l3=new JLabel("Depth: ");
JButton b1=new JButton("Oval");
JButton b2=new JButton("Round");
JPanel p=new JPanel(new GridLayout(4,2));
p.add(l1);
p.add(t1);
p.add(l2);
p.add(t2);
p.add(l3);
p.add(t3);
p.add(b1);
p.add(b2);
b1.addActionListener(this);
b2.addActionListener(this);
add(p);
setVisible(true);
pack();
}
public void actionPerformed(ActionEvent e){
String choice = e.getActionCommand();
int length=Integer.parseInt(t1.getText());
int width=Integer.parseInt(t2.getText());
int depth=Integer.parseInt(t3.getText());

if(choice.equals("Oval")){
int volume = ((length * width) * depth);
System.out.println(volume);
}
else if(choice.equals("Round")){
int volume = (((length/2)^2) * depth);
System.out.println(volume);
}
}
public static void main(String[]args){
JButtonExample b=new JButtonExample();
}
}

It will be helpful for you.
Thanks


Related Tutorials/Questions & Answers:
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
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
Advertisements
Decimal Format Issue Java
Decimal Format Issue Java  Decimal Format Issue Java
Java Calendar issue - Date Calendar
Java Calendar issue  Hi I have having weird situation with java Calendar, its driving me crazy. My requirenment is that i got a xml schema... to client to display time in Singapore timezone Here is the issue my Calendar Obj
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
Wants Suggestion about an issue. - Java Magazine
Wants Suggestion about an issue.  Hi all, I wish to develop a website like Social Networking Websites. For the development i think i should use Java Technology. So Request u guys to do suggest me what Design Pattern, What
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
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
JTABLE Issue
button " on a frame , by clicking this search button data will be retrived from DB... frame which gets open on click of search button. this JTable also has a back button to go back for another search. Now issue is -- when I put some input data
Query on Java Swing - Table Cell Issue - Swing AWT
Query on Java Swing - Table Cell Issue  Hi, I have a query on Java... are using JTable which has 6 columns which are editable. When I use the TAB button from... in order to set the cursor in the focused cell when the TAB button is used
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
issue on jcombobox
issue on jcombobox  i have JTextfield and JComboBox. there are several values in combobox.when i select a value from combobox how to make textfiled as a combobox.only few values in the combobox need this functionality. need
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
jdialogbox issue.
jdialogbox issue.  i have one button.when clicked on it has to show a dialog box.but even click on it several times it has to open dialog box only once. if it is already not opened atleast once,then only it has to open dialog
Button
Button  How to use image for button in JSF
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
JDialobBox issue
JDialobBox issue  i have one button.when clicked on it has to show a dialog box..but the dialog box should correctly display on top of buttonwhere button is placed in the panel,but not above region in the window..plese send code
Advertisements
 

 

 

DMCA.com