tikibobby
Member
Reputation: 0
Offline
Posts: 10
Referrals: 0
|
 |
« on: March 16, 2008, 05:53:33 PM » |
|
my problem i believe is simple, i have the interface but what i need is, if i have 4 text boxes, 2 on top and 2 on bottom and a button in the middle, 2 values are entered into the top 2 boxes, the when the button is pressed which ever box highest number, then the box directly below it has 1 added to it, i hope that makes sense
|
|
|
|
|
Logged
|
|
|
|
Arkie
Javaforums.net Admin
Senior Member
Reputation: 16
Developer @ Javaforums.net
Offline
Posts: 2593
Referrals: 13
|
 |
« Reply #1 on: March 16, 2008, 05:56:37 PM » |
|
So basically you need two input fields ( textfields ?), a button and two textareas to display the result?
|
|
|
|
|
Logged
|
|
|
|
tikibobby
Member
Reputation: 0
Offline
Posts: 10
Referrals: 0
|
 |
« Reply #2 on: March 16, 2008, 07:07:40 PM » |
|
yer, pretty much
|
|
|
|
|
Logged
|
|
|
|
Arkie
Javaforums.net Admin
Senior Member
Reputation: 16
Developer @ Javaforums.net
Offline
Posts: 2593
Referrals: 13
|
 |
« Reply #3 on: March 17, 2008, 05:23:51 AM » |
|
yer, pretty much
I'll write a demo later today.
|
|
|
|
|
Logged
|
|
|
|
tikibobby
Member
Reputation: 0
Offline
Posts: 10
Referrals: 0
|
 |
« Reply #4 on: March 17, 2008, 07:47:40 AM » |
|
thanks happy face, id appreciate it very much
|
|
|
|
|
Logged
|
|
|
|
Arkie
Javaforums.net Admin
Senior Member
Reputation: 16
Developer @ Javaforums.net
Offline
Posts: 2593
Referrals: 13
|
 |
« Reply #5 on: March 17, 2008, 03:18:55 PM » |
|
Something like this?  entering data in two text boxes, affecting 2 other text boxes Code:GeSHi (java): /* * By: HappyFace - www.engineeringserver.com */ import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JTextArea; import javax.swing.JTextField; public static void main (String[] args ){ System. out. println("By: HappyFace - www.engineeringserver.com"); new GuiWithTextArea(); } public GuiWithTextArea(){ setTitle("By: HappyFace"); getContentPane().setLayout(null); input1.setBounds(0,0, 99,20); getContentPane().add(input1); input2.setBounds(101,0, 100,20); getContentPane().add(input2); inputB.setBounds(50,21, 100,20); inputB.addActionListener(this); getContentPane().add(inputB); output1.setBounds(0,50, 99,40); output1.setEnabled(false); getContentPane().add(output1); output2.setBounds(101,50, 100,40); output2.setEnabled(false); getContentPane().add(output2); setSize(210,120); setLocationRelativeTo(null); setResizable(false); setVisible(true); } if(e.getSource() == inputB){ if(input1.getText() == null || input2.getText() == null){ } try{ int tmp1 = Integer. parseInt(input1. getText()); int tmp2 = Integer. parseInt(input2. getText()); if(tmp1 > tmp2){ tmp1 = tmp1+1; output2.setText(""); output1.setText("" + tmp1); } if(tmp1 < tmp2){ tmp2 = tmp2+1; output1.setText(""); output2.setText("" + tmp2); } } } } } }
Created by GeSHI 1.0.7.20
|
|
|
|
|
Logged
|
|
|
|
tikibobby
Member
Reputation: 0
Offline
Posts: 10
Referrals: 0
|
 |
« Reply #6 on: March 17, 2008, 03:29:46 PM » |
|
the layout is right, where has the 21 come from? has text box 2 had a higher number 21 times, i will test it after my guitar lesson which i have in 1 min, and let you know, cheers
|
|
|
|
|
Logged
|
|
|
|
Arkie
Javaforums.net Admin
Senior Member
Reputation: 16
Developer @ Javaforums.net
Offline
Posts: 2593
Referrals: 13
|
 |
« Reply #7 on: March 17, 2008, 03:31:09 PM » |
|
the layout is right, where has the 21 come from? has text box 2 had a higher number 21 times, i will test it after my guitar lesson which i have in 1 min, and let you know, cheers
Enter two numbers in the top 2 fields, press the button and the one with the highest number will have the 1 added in the ouput under the field with the highest number.
|
|
|
|
« Last Edit: March 17, 2008, 03:34:25 PM by HappyFace »
|
Logged
|
|
|
|
tikibobby
Member
Reputation: 0
Offline
Posts: 10
Referrals: 0
|
 |
« Reply #8 on: March 17, 2008, 03:39:52 PM » |
|
i appreciate your help, but its not working like that, im not sure what it is doing, but not what i said, in your latest repl, you have the right concept, but the program isnt doing that for me. if i enter 2 in the top left and 1 in the top right it should add 1 to the bottom left totalling 1, then if i enter the score again and the top left is higher, the bottom left should increase to 2. cheers
|
|
|
|
|
Logged
|
|
|
|
Arkie
Javaforums.net Admin
Senior Member
Reputation: 16
Developer @ Javaforums.net
Offline
Posts: 2593
Referrals: 13
|
 |
« Reply #9 on: March 17, 2008, 03:50:31 PM » |
|
i appreciate your help, but its not working like that, im not sure what it is doing, but not what i said, in your latest repl, you have the right concept, but the program isnt doing that for me. if i enter 2 in the top left and 1 in the top right it should add 1 to the bottom left totalling 1, then if i enter the score again and the top left is higher, the bottom left should increase to 2. cheers
Try this: GeSHi (java): package homework; /* * By: HappyFace - www.engineeringserver.com */ import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JFrame; import javax.swing.JTextArea; import javax.swing.JTextField; int outputTmp1; int outputTmp2; public static void main (String[] args ){ System. out. println("By: HappyFace - www.engineeringserver.com"); new GuiWithTextArea(); } public GuiWithTextArea(){ setTitle("By: HappyFace"); getContentPane().setLayout(null); input1.setBounds(0,0, 99,20); getContentPane().add(input1); input2.setBounds(101,0, 100,20); getContentPane().add(input2); inputB.setBounds(50,21, 100,20); inputB.addActionListener(this); getContentPane().add(inputB); output1.setBounds(0,50, 99,40); output1.setEnabled(false); getContentPane().add(output1); output2.setBounds(101,50, 100,40); output2.setEnabled(false); getContentPane().add(output2); setSize(210,120); setLocationRelativeTo(null); setResizable(false); setVisible(true); } if(e.getSource() == inputB){ if(input1.getText() == null || input2.getText() == null){ } try{ int tmp1 = Integer. parseInt(input1. getText()); int tmp2 = Integer. parseInt(input2. getText()); if(tmp1 > tmp2){ outputTmp1++; output1.setText("" + outputTmp1); } if(tmp1 < tmp2){ outputTmp2++; output2.setText("" + outputTmp2); } } } } } }
Created by GeSHI 1.0.7.20
|
|
|
|
|
Logged
|
|
|
|
tikibobby
Member
Reputation: 0
Offline
Posts: 10
Referrals: 0
|
 |
« Reply #10 on: March 17, 2008, 04:55:24 PM » |
|
yer thats what i was looking for thank you very much
|
|
|
|
|
Logged
|
|
|
|
Arkie
Javaforums.net Admin
Senior Member
Reputation: 16
Developer @ Javaforums.net
Offline
Posts: 2593
Referrals: 13
|
 |
« Reply #11 on: March 17, 2008, 05:03:57 PM » |
|
yer thats what i was looking for thank you very much
Sure np, glad it worked out well!
|
|
|
|
|
Logged
|
|
|
|
SwiftPost
Member
Reputation: 0
Offline
Posts: 60
Referrals: 0
|
 |
« Reply #12 on: March 17, 2008, 07:12:38 PM » |
|
I know the problem as been resolved. However could someone explain to me what all these boxes do? I am completly confused on what it actually dose. Sorry of this is such a stupid question.
|
|
|
|
|
Logged
|
|
|
|
Arkie
Javaforums.net Admin
Senior Member
Reputation: 16
Developer @ Javaforums.net
Offline
Posts: 2593
Referrals: 13
|
 |
« Reply #13 on: March 17, 2008, 07:50:24 PM » |
|
I know the problem as been resolved. However could someone explain to me what all these boxes do? I am completly confused on what it actually dose. Sorry of this is such a stupid question.
I've made it into an executable jar file, If you have Java 1.6 you can run this file here and see yourself what it does: http://www.engineeringser...tware/GuiWithTextArea.jar
|
|
|
|
|
Logged
|
|
|
|
tikibobby
Member
Reputation: 0
Offline
Posts: 10
Referrals: 0
|
 |
« Reply #14 on: March 18, 2008, 11:04:10 AM » |
|
that program works, efficiently, and does what i asked, but how could i do it without the "catch(NumberFormatException e1)" this is going to be put into part of my program, which is quite simple, and i dont understand the "catch(NumberFormatException e1)" as i dont really understand it, cheers
|
|
|
|
|
Logged
|
|
|
|
Arkie
Javaforums.net Admin
Senior Member
Reputation: 16
Developer @ Javaforums.net
Offline
Posts: 2593
Referrals: 13
|
 |
« Reply #15 on: March 18, 2008, 01:52:12 PM » |
|
Well just remove the try/catch but if you are entering a non digit an exception will come up so thats why i used a try/catch construction to catch the exception. (although it doesn't show anything when you press the button and enter a non digit in the 2 textfields the exception is handled in the background of the application)
|
|
|
|
|
Logged
|
|
|
|
BlueEew
Member
Reputation: 0
Offline
Gender: 
Posts: 100
Referrals: 0
|
 |
« Reply #16 on: March 19, 2008, 10:52:10 AM » |
|
I also don't understand what it dose. I downloaded the link you suggested to SwiftPost. However I do not know what I have to do with it. Maybe you can help?
|
|
|
|
|
Logged
|
|
|
|
|