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



Home Answers Viewqa Java-Beginners Java Button issue

Have Programming Question? Ask it here!
 
 
 


Anna
Java Button issue
1 Answer(s)      4 years and a month 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
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
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
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
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
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
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
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
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
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
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
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
Issue with Javascript
Issue with Javascript  Hi I created arrays in javascript in following way var myimages= new Array(); myimages[0]="iphone_pushups.png"; myimages[1]= "cricket.png"; myimages[2]= "july.png"; myimages[3]= "matrix.png
dialogbox issue
dialogbox issue  in my application,when i click on button it is showing dialobBox ,for this i added one action listenr.it is working fine.but,the dialob box is not in application environment.even i closed my application
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
Tomcat start up issue: SEVERE: Error listenerStart - Java Server Faces Questions
Tomcat start up issue: SEVERE: Error listenerStart    Hi When I deployed my web application( named: myApp) in Tomcat 5.5.25, I am getting the following issue and I am not able to access my application. SEVERE: Error
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
Grid rows delete issue
Grid rows delete issue  I have a grid having rows with Remove button to remove rows,But we also havae an facility to remove those rows on onchange... on onchange of dropdown then because of rows indexing issue,they can't get middle row
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
Read Issue itext
Read Issue itext  Hello, I m using itext to read data from pdf file.. Right now i m reading page wise data,but i want to extract data on each line... it manually afterwords.. thnx in advance Rohit   Java itext read pdf file
Read Issue itext
Read Issue itext  Hello, I m using itext to read data from pdf file.. Right now i m reading page wise data,but i want to extract data on each line... it manually afterwords.. thnx in advance Rohit   Java itext read pdf file
How to solve button problem - Java Beginners
How to solve button problem  I have created button (Open File Dialog) , List, JTabbedpane and MenuBar . By clicking btnBrowse button I am getting... equal space So button size also increasing. Could you please guide me how
semantic issue xcode 4.2
semantic issue xcode 4.2  I have updated xcode 4.0 to 4.2 .. but once i open any application in this new version of xcode ..it throws lots of semantic issue. Can anyone please explain why it occurs and how to resolve
Advertisements
 

 

 

DMCA.com