java - Text Box not working properly -


I wrote a program for an applet that you want to display different text in the text box when pressing a button Are there. There is no error in my program when I compiled it, but the text box is not displayed correctly I do not know what is wrong with it. Here is my code

  import java.awt. *; Import java.awt.event. *; Public class color {button button 1; Button Button 2; Button button3; Label label 1; Textfield ogtextfilled 1; Public static zero main (string algos []) {colors c = new colors (); } Public color () {frame F = new frame ("color"); Button Button 1 = New Button ("Blue"); Button1.setBounds (10,305,120,75); Button1.addMouseListener (New MyMouseListener1 ()); Button Button 2 = New Button ("Red"); Button2.setBounds (140,305,120,75); Button2.addMouseListener (New MyMouseListener2 ()); Button Button 3 = New Button ("Yellow"); Button3.setBounds (270,305,120,75); Button 3.addMouseListener (New MyMouseListener3 ()); F.add (Button1); F.add (Button2); F.add (Button3); Label1 = new label ("click on a button to reveal text"); Label1.setBounds (20,105,200,25); F.add (label1); ObjTextField1 = New TextField ("Which Color?", 15); ObjTextField1.setBounds (20,75,125,50); F.add (objTextField1); F.add (label1); F.add (objTextField1); F.addWindowListener (New Window Adapter) {Public Zero Window Closed (Window Event We) {System.exit (0);}}); F.setSize (400400); F.setVisible (true); } Public class MyMouseListener1 provides MouseAdapter {public void mouseClicked (mouse events) {objTextField1.setText ("blue"); }} Public Class MyMouseListener2 has expanded the MOUdeptter {public zero mouseclutter (mouse Event Me) {objTextField1.setText ("Red"); }} Public class MyMouseListener3 offers mouse adapter {public zero mouseClicked (mouse Event me) {objTextField1.setText ("Yellow"); }}}  

when clicked on a button Is a actionEvent .

You should use one instead of MouseListener .

Pre> button.addActionListener (example);


Comments

Popular posts from this blog

java - org.apache.http.ProtocolException: Target host is not specified -

java - Gradle dependencies: compile project by relative path -

ruby on rails - Object doesn't support #inspect when used with .include -