You are viewing our Forum Archives. To view or take place in current topics click here.
Java | Basic GUI Problem | Help?
Posted:

Java | Basic GUI Problem | Help?Posted:

Zoo
  • TTG Addict
Status: Offline
Joined: Aug 13, 201113Year Member
Posts: 2,113
Reputation Power: 103
Status: Offline
Joined: Aug 13, 201113Year Member
Posts: 2,113
Reputation Power: 103
Okay, so I am following RDCA's youtube tutorials to help me learn, and I came to Hello World with GUI. I made the following code, so it wouldn't be Hello World, but add. I get an error, and can't debug or run it. Just paste the code in eclipse and see what I mean..

import java.awt.FlowLayout;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JButton;



public class gui extends JFrame {
   private JLabel label1;
   private JButton Addition;
   public gui(){
   super("Options");
   setLayout(new FlowLayout());
   label1 = new JLabel("Add");
   label1.setToolTipText("Addition");
   add(label1);
   Addition = new JButton("Click");
      
   HandlerClass handler = new HandlerClass();
   Addition.addActionListener(handler);
   
   add(Addition);
      
   }
   
private class HandlerClass implements ActionListener{
public void actionperformed(ActionEvent event){

   JOptionPane.showMessageDialog(null, "Add");
}


   
   
}
   
}

#2. Posted:
ChromeWolf
  • New Member
Status: Offline
Joined: Dec 18, 201113Year Member
Posts: 33
Reputation Power: 1
Status: Offline
Joined: Dec 18, 201113Year Member
Posts: 33
Reputation Power: 1
Can you post the error you're getting
#3. Posted:
CoNdEmR
  • Summer 2022
Status: Offline
Joined: Apr 29, 200915Year Member
Posts: 4,420
Reputation Power: 1211
Status: Offline
Joined: Apr 29, 200915Year Member
Posts: 4,420
Reputation Power: 1211
Is this the only code you have? You have no main method to call this function.
#4. Posted:
Zoo
  • Christmas!
Status: Offline
Joined: Aug 13, 201113Year Member
Posts: 2,113
Reputation Power: 103
Status: Offline
Joined: Aug 13, 201113Year Member
Posts: 2,113
Reputation Power: 103
CoNdEmR wrote Is this the only code you have? You have no main method to call this function.


Ill add the entire code for the whole project, and upload some pictures when I get home.
Jump to:
You are viewing our Forum Archives. To view or take place in current topics click here.