Results 1 to 8 of 8
Thread: Multithreading Gui
- 10-13-2010, 11:14 AM #1
Member
- Join Date
- Oct 2010
- Posts
- 5
- Rep Power
- 0
Multithreading Gui
frns,please help me with this code....it shows some exception.i am new to java and i dunno how to solve this. :(
Java Code:import java.awt.*; import java.awt.event.*;//for specifying windows events import javax.swing.*; import java.lang.*; public class FrontEn implements ActionListener,Runnable { JTextField jav,it,c; Frame f; JButton Submit; int aa,bb,cc,tot; float avg,x; FrontEn() //Constructor that has the basic GUI code... { f=new Frame("Progress Calculator"); JLabel l1=new JLabel("Enter the marks here:"); f.add(l1); Panel p=new Panel(); Panel p1=new Panel(); JLabel java=new JLabel("Java"); jav=new JTextField(3); System.out.println(" "); JLabel itc=new JLabel("Information Theorey"); it=new JTextField(3); JLabel cn=new JLabel("Computer Networks"); c=new JTextField(3); p.setLayout(new GridLayout(3,1)); p.add(java); p.add(itc); p.add(cn); p.add(jav); p.add(it); p.add(c); Submit=new JButton("Submit"); p.add(Submit); p1.add(p); f.add(p1,BorderLayout.CENTER); f.setSize(500,300); f.setVisible(true); //assigning the values given in the textfield to the integer variables declared in claSS aa=Integer.parseInt(jav.getText()); bb=Integer.parseInt(it.getText()); cc=Integer.parseInt(c.getText()); Submit.addActionListener(this); //creating the thread by implementing Runnable Thread T=new Thread(this); T.start(); } public void actionPerformed(ActionEvent ae) { String str = ae.getActionCommand(); //To check if the Submit button is pressed or not if(str.equals("Submit")) { //defining wat shud b done afte the button is pressed f.setVisible(false); tot=aa+bb+cc; JFrame f2=new JFrame("Result"); f2.addWindowListener(new WindowAdapter(){ public void windowClosing(WindowEvent e){ System.exit(0); }}); JLabel Total=new JLabel("TOTAL:"); JLabel t=new JLabel(Float.toString(tot)); JLabel avv=new JLabel("AVERAGE"); JLabel av=new JLabel(Float.toString(x)); f2.setLayout(new GridLayout(3,1)); f2.add(Total); f2.add(t); f2.add(avv); f2.add(av); f2.setSize(300,300); f2.setVisible(true); } } //Thread's RUN function public void run() { try{ avg=(aa+bb+cc)/3; x=avg;} catch(Exception e) { } } public static void main(String ar[]) { new FrontEn(); } }
When i tried executing,it showed following error...
G:\javaessentials>javac FrontEn.java
G:\javaessentials>java FrontEn
Exception in thread "main" java.lang.NumberFormatException: For input string: ""
at java.lang.NumberFormatException.forInputString(Unk nown Source)
at java.lang.Integer.parseInt(Unknown Source)
at java.lang.Integer.parseInt(Unknown Source)
at FrontEn.<init>(FrontEn.java:39)
at FrontEn.main(FrontEn.java:88)
pls help me....Last edited by BUGSIE91; 10-13-2010 at 01:39 PM.
- 10-13-2010, 11:29 AM #2
I don't read unformatted code, but the error you posted has nothing to do with either multithreading or a GUI.
What number would you expect to result out of parsing the String "" (aka the empty String)?
db
- 10-13-2010, 11:31 AM #3
Member
- Join Date
- Oct 2010
- Posts
- 5
- Rep Power
- 0
this app actually gets 3 numbers...adds and gives the total and then the average is caluclated...so the unknown source indicates at the numbers that are to b given as input....i need to get the inputs via textfields....but wen i run,i get this error...
-
As Darryl suggests, please edit your post so that it shows formatted code.
-
You're trying to parse the JTextField on application creation, before the user has entered any data. You should
1) Do all your parsing in the actionPerformed method so that it occurs after data has been entered.
2) Do not mix AWT and Swing components but rather use all Swing components (e.g., use a JFrame not a Frame).
3) Next time, please only post formatted code. If you make it easier for us to read your post, more will help you quicker.
4) Next time show which line is causing the exception (the exception gives line numbers but this is only valid in your actual source file, not in the code we see posted above).
Luck.
- 10-13-2010, 01:37 PM #6
Member
- Join Date
- Oct 2010
- Posts
- 5
- Rep Power
- 0
i dunno what u mean by formatting...sorry...i shud add lot of comment line ah???
- 10-13-2010, 01:47 PM #7
Member
- Join Date
- Oct 2010
- Posts
- 5
- Rep Power
- 0
@Fubarable sir,i changed the code as u said....now the statements in the Run() of the thread is not working :| ...i am getting the total,which is displayed in the actionListener function and not the average tat is calculated by the thread
- 10-13-2010, 02:20 PM #8
Member
- Join Date
- Oct 2010
- Posts
- 5
- Rep Power
- 0
Similar Threads
-
Want to know about Multithreading.
By Chetans in forum Threads and SynchronizationReplies: 1Last Post: 03-19-2010, 07:50 AM -
Multithreading in java
By MuslimCoder in forum New To JavaReplies: 5Last Post: 02-20-2010, 08:16 PM -
Log 4j Multithreading
By joe2010 in forum Threads and SynchronizationReplies: 1Last Post: 01-31-2010, 03:48 AM -
multithreading
By shilpa.krishna in forum New To JavaReplies: 2Last Post: 06-27-2008, 04:18 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks