Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Beginning Java
Search Coderanch
Advance search
Google search
Register / Login
Post Reply
Bookmark Topic
Watch Topic
New Topic
programming forums
Java
Mobile
Certification
Databases
Caching
Books
Engineering
Micro Controllers
OS
Languages
Paradigms
IDEs
Build Tools
Frameworks
Application Servers
Open Source
This Site
Careers
Other
Pie Elite
all forums
this forum made possible by our volunteer staff, including ...
Marshals:
Campbell Ritchie
Jeanne Boyarsky
Ron McLeod
Paul Clapham
Liutauras Vilda
Sheriffs:
paul wheaton
Rob Spoor
Devaka Cooray
Saloon Keepers:
Stephan van Hulst
Tim Holloway
Carey Brown
Frits Walraven
Tim Moores
Bartenders:
Mikalai Zaikin
Forum:
Beginning Java
Check Boxes
Jodi Clackers
Greenhorn
Posts: 4
posted 19 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
hello ppl....having trouble with the check boxes in this code. I've never attempted to do this before, prolly why i have a 'fumbling around in the dark' feeling.
Any feedback would be muchly appreciated =0)
import java.awt.*; import java.awt.event.*; import java.text.*; import javax.swing.*; public class extra extends Frame implements ActionListener { private TextField num1, num2, num3, num4, num5, num6, num7, num8, num9, num10; private Label L1, L2, L3, L4, L5, L6, L7, L8, name, answer; private Button calc, print, clear, exit; public double final_answer; private MessageBox msg; private JCheckBox ch1, ch2,ch3, ch4, ch5, ch6,ch7, ch8; public extra() { ActionListener cblistener = new CheckBoxListener(); ch1 = new JCheckBox("L1",true); ch2 = new JCheckBox("L2",true); ch3 = new JCheckBox("L3",true); ch4 = new JCheckBox("L4",true); ch5 = new JCheckBox("L5",true); ch6 = new JCheckBox("L6",true); ch7 = new JCheckBox("L7",true); ch8 = new JCheckBox("L8",true); ch1.addActionListener(cblistener); ch2.addActionListener(cblistener); ch3.addActionListener(cblistener); ch4.addActionListener(cblistener); ch5.addActionListener(cblistener); ch6.addActionListener(cblistener); ch7.addActionListener(cblistener); ch8.addActionListener(cblistener); setSize(800,500); setLayout(new FlowLayout(FlowLayout.RIGHT)); L1=new Label (" CB-CAT5E-1 1M CAT.5E UTP CABLE RJ45M"); num1=new TextField(5); L2=new Label (" CB-CAT5E-10 10M CAT.5E UTP CABLE RJ45M"); num2=new TextField(15); num2.setEditable(false); L3=new Label(" CB-CAT6-1 1M AT6 UTP CABLE RJ45M"); num3=new TextField(15); num3.setEditable(false); L4=new Label(" CB-CAT6-10 10M CAT6 UTP CABLE RJ45M"); num4=new TextField(15); num4.setEditable(false); L5=new Label(" CB-CAT5ECS-2 2M CAT.5E UTP CROSSOVER CABLE RJ45M"); num5=new TextField(15); num5.setEditable(false); L6=new Label(" CB-CAT5ECS-10 10M CAT.5E UTP CROSSOVER CABLE RJ45M"); num6=new TextField(15); num6.setEditable(false); L7=new Label(" CB-CAT6CS-2 2M CAT6 UTP CROSSOVER CABLE RJ45M"); num7=new TextField(15); num7.setEditable(false); L8=new Label(" CB-CAT6CS-10 10M CAT6 UTP CROSSOVER CABLE RJ45M"); num8=new TextField(15); num8.setEditable(false); setLayout(new FlowLayout(FlowLayout.LEFT)); name=new Label("Customer Name:"); num9=new TextField(15); num9.setEditable(false); answer=new Label("The cost of your purchase is: "); num10=new TextField(15); num10.setEditable(false); calc=new Button("Calculate"); calc.addActionListener(this); print=new Button("Print Cost"); calc.addActionListener(this); clear=new Button("Clear"); clear.addActionListener(this); exit=new Button ("Exit"); exit.addActionListener(this); add(L1); add(num1); add(L2); add(num2); add(L3); add(num3); add(L4); add(num4); add(L5); add(num5); add(L6); add(num6); add(L7); add(num7); add(L8); add(num8); add(name); add(num9); add(answer); add(num10); add(calc); add(print); add(clear); add(exit); } public void actionPerformed(ActionEvent e) { DecimalFormat twoDigits = new DecimalFormat("0.00"); if(e.getSource() == calc) { try{ final_answer= Double.parseDouble(num1.getText()) + Double.parseDouble(num2.getText()); answer.setText(twoDigits.format(final_answer)); } catch(NumberFormatException nfe) { msg.setVisible(true); } } if(e.getSource() == clear) { num1.setText(""); num2.setText(""); answer.setText(""); } if(e.getSource() == exit) { System.exit(0); } } public static void main(String args[]) { extra e= new extra(); } }
Dirk Schreckmann
Sheriff
Posts: 7023
posted 19 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Moving this to
the Swing / AWT / SWT / JFace forum
...
[ September 05, 2004: Message edited by: Dirk Schreckmann ]
[
How To Ask Good Questions
] [
JavaRanch FAQ Wiki
] [
JavaRanch Radio
]
Don't get me started about those stupid
light bulbs
.
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
recursive method
How to make the window (JPanel?) bigger in gridbaglayout
easier way to extract int from string?
applet problem
Help with Dice generator
More...