The Action Driver Class when it runs it just brings up a small box with java logo and close and minimize options thats all...... I have reviewd the code over and over and my instuctor said to just review my work... I am so lost....
Buttons don't work or even appear in my Java GUI in JGRASP
**Action Driver Class**
class ActionsDriver
{
public static void main (String[] args)
{
Actions eg = new Actions();
}
}
**Action Class**
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class Actions extends JFrame implements ActionListener
{
private JFrame programFrame;
private JPanel programPanel1;
private JPanel programPanel2;
private JButton programButton1;
private JButton programButton2;
private JButton programButton3;
private JButton programButton4;
private JButton programButton5;
private JTextField programTextField;
public Actions()
{
programFrame = new JFrame("ENTD 380 Assignment #5");
programFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
programFrame.setSize(600,400);
programPanel1 = new JPanel();
programPanel2 = new JPanel();
programButton1 = new JButton("Button 1");
programButton2 = new JButton("Button 2");
programButton3 = new JButton("Button 3");
programButton4 = new JButton("Button 4");
programButton5 = new JButton("Button 5");
programTextField = new JTextField("None of the buttons have been pressed yet!");
programTextField.setHorizontalAlignment(JTextField.CENTER);
programButton1.addActionListener(this);
programButton2.addActionListener(this);
programButton3.addActionListener(this);
programButton4.addActionListener(this);
programButton5.addActionListener(this);
programPanel1.add(programButton1);
programPanel1.add(programButton2);
programPanel1.add(programButton3);
programPanel1.add(programButton4);
programPanel1.add(programButton5);
programPanel2.add(programTextField);
programFrame.pack();
programFrame.setResizable(false);
programFrame.setVisible(true);
}
public void actionPerformed(ActionEvent event)
{
if (event.getSource() == programButton1)
{
programTextField.setText("Button 1 was pressed!");
}
else if (event.getSource() == programButton2)
{
programTextField.setText("Button 2 was pressed!");
}
else if (event.getSource() == programButton3)
{
programTextField.setText("Button 3 was pressed!");
}
else if (event.getSource() == programButton4)
{
programTextField.setText("Button 4 was pressed!");
}
else
{
programTextField.setText("Button 5 was pressed!");
}
}
}
rproffitt 2,662 "Nothing to see here." Moderator
JamesCherrill 4,733 Most Valuable Poster Team Colleague Featured Poster
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.