• Post Reply Bookmark Topic Watch Topic
  • New Topic

Why won't it display inside the JFrame?  RSS feed

 
Matthew Buska
Greenhorn
Posts: 11
Android Eclipse IDE Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi I was wondering if anybody could tell me why nothing is showing up inside the window?

import javax.swing.*;
import java.awt.*;
import java.awt.event.*;

public class JDemoResistance extends JFrame implements ActionListener
{
JButton pushButton1 = new JButton();
JLabel reason1 = new JLabel("Too expensive.");
JButton pushButton2 = new JButton();
JLabel reason2 = new JLabel("Not exactly what you need.");
JButton pushButton3 = new JButton();
JLabel reason3 = new JLabel("Took to long to develop.");
JButton pushButton4 = new JButton();
JLabel reason4 = new JLabel("Found a better program.");
JButton pushButton5 = new JButton();
JLabel reason5 = new JLabel("Got caught and had to buy the wife/girlfriend something.");

public JDemoResistance()
{
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel pane = new JPanel();
pane.add(pushButton1, reason1);
pane.add(pushButton2, reason2);
pane.add(pushButton3, reason3);
pane.add(pushButton4, reason4);
pane.add(pushButton5, reason5);
setContentPane(pane);
pushButton1.addActionListener(this);
pushButton2.addActionListener(this);
pushButton3.addActionListener(this);
pushButton4.addActionListener(this);
pushButton5.addActionListener(this);
}

public static void main(String[] args)
{
JFrame aFrame = new JFrame("Reasons a customer might not buy your product.");
aFrame.setSize(500,450);
aFrame.setVisible(true);
}

public void actionPerformed(ActionEvent e)
{
Object source = e.getSource();

if(source == pushButton1)
{
reason2.setText("Not exactly what you need.");
reason3.setText("Took to long to develop.");
reason4.setText("Found a better program.");
reason5.setText("Got caught and had to buy the wife/girlfriend something.");
}
else if(source == pushButton2)
{
reason1.setText("Too expensive.");
reason3.setText("Took to long to develop.");
reason4.setText("Found a better program.");
reason5.setText("Got caught and had to buy the wife/girlfriend something.");
}
else if(source == pushButton3)
{
reason1.setText("Too expensive.");
reason2.setText("Not exactly what you need.");
reason4.setText("Found a better program.");
reason5.setText("Got caught and had to buy the wife/girlfriend something.");
}
else if(source == pushButton4)
{
reason1.setText("Too expensive.");
reason2.setText("Not exactly what you need.");
reason3.setText("Took to long to develop.");
reason5.setText("Got caught and had to buy the wife/girlfriend something.");
}
else
{
reason1.setText("Too expensive.");
reason2.setText("Not exactly what you need.");
reason3.setText("Took to long to develop.");
reason4.setText("Found a better program.");
}
}
}
 
Joe Ess
Bartender
Posts: 9429
12
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For starters:

You create a JFrame and don't add anything to it.
Always a good link: Creating a GUI with JFC/Swing
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!