user interface - Simple GUI question in java -


I'm trying a very simple GUI in Java. I've just made a small GUI with the buttons and when we Click on each button, it opens a website

so I have 3 buttons. = Button1 = Gmail Button2 Google Button3 = Yahoo!

When I click on button1, sometimes it opens Gmail or Google or Yahoo. The same problem with other buttons also

Why

Here is my very simple code:.

  import java.awt *; Import java.awt.event. *; Import java.io * *; Import java.util.logging.Level; Import java.util.logging.Logger; The public class Gui has the frame image window listener, action lustner {// textfield text = new textfield (20); Button A, B, C; Process P1, P2, P3; // Private-Ent Nucleicics = 0; Public static zero major (string [] args) {Gui Mivando = New Gui ("Miquelon"); MyWindow.setSize (350,100); MyWindow.setVisible (true); } Public Gui (string title) {super (title); Setout (new flow layout ()); AddWindowListener (this); A = New Button ("Gmail"); B = New Button ("Google"); C = New Button ("Yahoo"); Add one); (B) add; (C) add; // add words); A.addActionListener (this); B.addActionListener (this); C.addActionListener (this); } Public Zero Functionality (Action Event e) {{p1 = Runtime.jetantime ()). Exec ("CMD / C Start https://mail.google.com"); P2 = Runtime.getRuntime (). Exec ("CMD / C Start https://google.com"); P3 = RuntimeGetRight (). Exec ("CMD / C Start https://yahoo.com"); }} Hold (IOException pre) {Logger.getLogger (Gui.class.getName ()) log in (Level.SEVERE, null, east). }} Public Zero Window Closed (WindowEndE) {Settlement (); System.exit (0); } Public Zero WindowOpened (WindowEvent E) {} Public Zero WindowActivated (WindowEvent E) {} Public Zero WindowIconified (WindowEvent e) {} Public Zero WindowDeiconified (WindowEvent E) {} Public Zero WindowDeactivated (WindowEvent e) {} Public Zero WindowClosed WindowEvent e) {}}   

thanks

all your actionPerformed Three is running you need to use actionPerformed to determine which button was pressed, and then run this command

  public shoe Somewhere actionPerformed (ActionEvent e) {string = "". If (e.getSource () == a) address = "https://mail.google.com"; Else if (e.getSource () == b) address = "https://google.com"; Else if (e.getSource () == c) address = "https://yahoo.com"; Other Returns; // Not one of the three buttons, get out! Try // // Only if you want to do something with this later need to store the process // I just give my dangle :) It works for me! Runtime.GetRime () Exec ("CMD / C Start" + address); } Hold (IOException pre) {Logger.getLogger (Gui.class.getName ()). Log (Level.SEVERE, null, ex); }}    

Comments