Saturday, 12 May 2012

Can anyone help with this ActionListener in my java program?


i'm trying create program convert inches centimeters. made 1 displayed info in console. (you'd type in number of inches , it'd display how many centimeters that'd be) i'm trying make 1 using java swing , have window pops stuck on getting action listener. can offer advice or correct code?
here's code:
code:
 import javax.swing.*;  import java.awt.color; import java.awt.flowlayout; import java.awt.event.actionevent; import java.awt.event.actionlistener;  public class cw extends jframe implements actionlistener {  	private jbutton convert; 	jtextarea text = new jtextarea(1,20); 	private int conversion = 0; 	 	 	 	public cw() { 		setlayout(new flowlayout()); 		setvisible(true); 		setdefaultcloseoperation(jframe.exit_on_close); 		setsize(400,200); 		convert = new jbutton("convert"); 		add(convert); 		add(text); 		convert.addactionlistener(this);  		 	}    public void actionperformed(actionevent e) { 	object source = e.getsource(); 	 		}  		 	}  
 

what tutorial or book using? or taking class?


step 1 make action simple, show text that's in text field. that's simple yet observable action. if don't know how it, need study how user input in swing works. not button-click user input, plain old text entered in text field.

step 2 make action validate contents of text field. i.e. numeric? presumably had in terminal oriented program.

step 3 convert text number , perform calculation. again, did in terminal program, right?

step 4 figure out how , display result of calculation. study swing again, , component can display text, or numbers converted text.
 


Forums Macs Mac Programming


  • iPhone
  • Mac OS & System Software
  • iPad
  • Apple Watch
  • Notebooks
  • iTunes
  • Apple ID
  • iCloud
  • Desktop Computers
  • Apple Music
  • Professional Applications
  • iPod
  • iWork
  • Apple TV
  • iLife
  • Wireless

No comments:

Post a Comment