Welcome, Guest. Please login or register.
Did you miss your activation email?
Pages: [1]   Go Down
  Print  
Author Topic: entering data in two text boxes, affecting 2 other text boxes  (Read 3055 times)
0 Members and 1 Guest are viewing this topic.
tikibobby
Member
*

Reputation: 0
Offline Offline
Posts: 10
Referrals: 0

Awards
« 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 Offline
Posts: 2593
Referrals: 13

WWW Awards
« 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

Java and .NET developer

To students: It doesn't matter how hard you've studied; the material won't be on the exam anyway.

Fan of http://www.retardedweblogger.com
Oh man, too much stuff to do in so little time.

http://img222.imageshack....707/arkietomatoesmall.jpg
Blizzcon 2k9 Grubby and Cassandra Ng engaged ! <3
Triple D, eerste Denken Dan Doen
tikibobby
Member
*

Reputation: 0
Offline Offline
Posts: 10
Referrals: 0

Awards
« 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 Offline
Posts: 2593
Referrals: 13

WWW Awards
« Reply #3 on: March 17, 2008, 05:23:51 AM »

yer, pretty much

I'll write a demo later today.
Logged

Java and .NET developer

To students: It doesn't matter how hard you've studied; the material won't be on the exam anyway.

Fan of http://www.retardedweblogger.com
Oh man, too much stuff to do in so little time.

http://img222.imageshack....707/arkietomatoesmall.jpg
Blizzcon 2k9 Grubby and Cassandra Ng engaged ! <3
Triple D, eerste Denken Dan Doen
tikibobby
Member
*

Reputation: 0
Offline Offline
Posts: 10
Referrals: 0

Awards
« 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 Offline
Posts: 2593
Referrals: 13

WWW Awards
« Reply #5 on: March 17, 2008, 03:18:55 PM »

Something like this?
http://img369.imageshack.us/img369/8525/tmpjz0.png
entering data in two text boxes, affecting 2 other text boxes



Code:


Code
GeSHi (java):
  1. /*
  2.  * By: HappyFace - www.engineeringserver.com
  3.  */
  4.  
  5. import java.awt.event.ActionEvent;
  6. import java.awt.event.ActionListener;
  7.  
  8. import javax.swing.JButton;
  9. import javax.swing.JFrame;
  10. import javax.swing.JTextArea;
  11. import javax.swing.JTextField;
  12.  
  13. public class GuiWithTextArea extends JFrame implements ActionListener{
  14. private JTextField input1, input2;
  15. private JButton inputB = new JButton("Click");
  16. private JTextArea output1, output2;
  17.  
  18.  
  19. public static void main(String[] args){
  20. System.out.println("By: HappyFace - www.engineeringserver.com");
  21. new GuiWithTextArea();
  22. }
  23.  
  24. public GuiWithTextArea(){
  25. setTitle("By: HappyFace");
  26. getContentPane().setLayout(null);
  27. input1 = new JTextField();
  28. input1.setBounds(0,0, 99,20);
  29. getContentPane().add(input1);
  30.  
  31. input2 = new JTextField();
  32. input2.setBounds(101,0, 100,20);
  33. getContentPane().add(input2);
  34.  
  35. inputB = new JButton("Click me");
  36. inputB.setBounds(50,21, 100,20);
  37. inputB.addActionListener(this);
  38. getContentPane().add(inputB);
  39.  
  40. output1 = new JTextArea();
  41. output1.setBounds(0,50, 99,40);
  42. output1.setEnabled(false);
  43. getContentPane().add(output1);
  44.  
  45. output2 = new JTextArea();
  46. output2.setBounds(101,50, 100,40);
  47. output2.setEnabled(false);
  48. getContentPane().add(output2);
  49. setSize(210,120);
  50. setLocationRelativeTo(null);
  51. setResizable(false);
  52. setVisible(true);
  53. }
  54.  
  55. public void actionPerformed(ActionEvent e) {
  56. if(e.getSource() == inputB){
  57.  
  58. if(input1.getText() == null || input2.getText() == null){
  59.  
  60. }
  61. try{
  62. int tmp1 = Integer.parseInt(input1.getText());
  63. int tmp2 = Integer.parseInt(input2.getText());
  64.  
  65.  
  66. if(tmp1 > tmp2){
  67. tmp1 = tmp1+1;
  68. output2.setText("");
  69. output1.setText("" + tmp1);
  70. }
  71.  
  72. if(tmp1 < tmp2){
  73. tmp2 = tmp2+1;
  74. output1.setText("");
  75. output2.setText("" + tmp2);
  76. }
  77. }
  78. }
  79. }
  80. }
  81. }
  82.  
Created by GeSHI 1.0.7.20
Logged

Java and .NET developer

To students: It doesn't matter how hard you've studied; the material won't be on the exam anyway.

Fan of http://www.retardedweblogger.com
Oh man, too much stuff to do in so little time.

http://img222.imageshack....707/arkietomatoesmall.jpg
Blizzcon 2k9 Grubby and Cassandra Ng engaged ! <3
Triple D, eerste Denken Dan Doen
tikibobby
Member
*

Reputation: 0
Offline Offline
Posts: 10
Referrals: 0

Awards
« 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 Offline
Posts: 2593
Referrals: 13

WWW Awards
« 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

Java and .NET developer

To students: It doesn't matter how hard you've studied; the material won't be on the exam anyway.

Fan of http://www.retardedweblogger.com
Oh man, too much stuff to do in so little time.

http://img222.imageshack....707/arkietomatoesmall.jpg
Blizzcon 2k9 Grubby and Cassandra Ng engaged ! <3
Triple D, eerste Denken Dan Doen
tikibobby
Member
*

Reputation: 0
Offline Offline
Posts: 10
Referrals: 0

Awards
« 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 Offline
Posts: 2593
Referrals: 13

WWW Awards
« 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:

Code
GeSHi (java):
  1. package homework;
  2. /*
  3.  * By: HappyFace - www.engineeringserver.com
  4.  */
  5.  
  6. import java.awt.event.ActionEvent;
  7. import java.awt.event.ActionListener;
  8.  
  9. import javax.swing.JButton;
  10. import javax.swing.JFrame;
  11. import javax.swing.JTextArea;
  12. import javax.swing.JTextField;
  13.  
  14. public class GuiWithTextArea extends JFrame implements ActionListener{
  15. private JTextField input1, input2;
  16. private JButton inputB = new JButton("Click");
  17. private JTextArea output1, output2;
  18.  
  19. int outputTmp1;
  20. int outputTmp2;
  21.  
  22. public static void main(String[] args){
  23. System.out.println("By: HappyFace - www.engineeringserver.com");
  24. new GuiWithTextArea();
  25. }
  26.  
  27. public GuiWithTextArea(){
  28. setTitle("By: HappyFace");
  29. getContentPane().setLayout(null);
  30. input1 = new JTextField();
  31. input1.setBounds(0,0, 99,20);
  32. getContentPane().add(input1);
  33.  
  34. input2 = new JTextField();
  35. input2.setBounds(101,0, 100,20);
  36. getContentPane().add(input2);
  37.  
  38. inputB = new JButton("Click me");
  39. inputB.setBounds(50,21, 100,20);
  40. inputB.addActionListener(this);
  41. getContentPane().add(inputB);
  42.  
  43. output1 = new JTextArea();
  44. output1.setBounds(0,50, 99,40);
  45. output1.setEnabled(false);
  46. getContentPane().add(output1);
  47.  
  48. output2 = new JTextArea();
  49. output2.setBounds(101,50, 100,40);
  50. output2.setEnabled(false);
  51. getContentPane().add(output2);
  52. setSize(210,120);
  53. setLocationRelativeTo(null);
  54. setResizable(false);
  55. setVisible(true);
  56. }
  57.  
  58. public void actionPerformed(ActionEvent e) {
  59.  
  60. if(e.getSource() == inputB){
  61.  
  62. if(input1.getText() == null || input2.getText() == null){
  63.  
  64. }
  65. try{
  66. int tmp1 = Integer.parseInt(input1.getText());
  67. int tmp2 = Integer.parseInt(input2.getText());
  68.  
  69.  
  70. if(tmp1 > tmp2){
  71. outputTmp1++;
  72. output1.setText("" + outputTmp1);
  73. }
  74.  
  75. if(tmp1 < tmp2){
  76. outputTmp2++;
  77. output2.setText("" + outputTmp2);
  78. }
  79. }
  80. }
  81. }
  82. }
  83. }
  84.  
Created by GeSHI 1.0.7.20
Logged

Java and .NET developer

To students: It doesn't matter how hard you've studied; the material won't be on the exam anyway.

Fan of http://www.retardedweblogger.com
Oh man, too much stuff to do in so little time.

http://img222.imageshack....707/arkietomatoesmall.jpg
Blizzcon 2k9 Grubby and Cassandra Ng engaged ! <3
Triple D, eerste Denken Dan Doen
tikibobby
Member
*

Reputation: 0
Offline Offline
Posts: 10
Referrals: 0

Awards
« 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 Offline
Posts: 2593
Referrals: 13

WWW Awards
« 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

Java and .NET developer

To students: It doesn't matter how hard you've studied; the material won't be on the exam anyway.

Fan of http://www.retardedweblogger.com
Oh man, too much stuff to do in so little time.

http://img222.imageshack....707/arkietomatoesmall.jpg
Blizzcon 2k9 Grubby and Cassandra Ng engaged ! <3
Triple D, eerste Denken Dan Doen
SwiftPost
Member
*

Reputation: 0
Offline Offline
Posts: 60
Referrals: 0

Awards
« 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 Offline
Posts: 2593
Referrals: 13

WWW Awards
« 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

Java and .NET developer

To students: It doesn't matter how hard you've studied; the material won't be on the exam anyway.

Fan of http://www.retardedweblogger.com
Oh man, too much stuff to do in so little time.

http://img222.imageshack....707/arkietomatoesmall.jpg
Blizzcon 2k9 Grubby and Cassandra Ng engaged ! <3
Triple D, eerste Denken Dan Doen
tikibobby
Member
*

Reputation: 0
Offline Offline
Posts: 10
Referrals: 0

Awards
« 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 Offline
Posts: 2593
Referrals: 13

WWW Awards
« 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

Java and .NET developer

To students: It doesn't matter how hard you've studied; the material won't be on the exam anyway.

Fan of http://www.retardedweblogger.com
Oh man, too much stuff to do in so little time.

http://img222.imageshack....707/arkietomatoesmall.jpg
Blizzcon 2k9 Grubby and Cassandra Ng engaged ! <3
Triple D, eerste Denken Dan Doen
BlueEew
Member
*

Reputation: 0
Offline Offline
Gender: Male
Posts: 100
Referrals: 0

Awards
« 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

Pages: [1]   Go Up
  Print  
 
Jump to:  

Your Ad Here