Program is compiling but crashes

Shane_Kieran

Estimable
Sep 3, 2015
1
0
4,510
0
My GUI Program will compile and run but will not display my GUI

Here is the code:
Ignore the pictures Btw

import javax.swing.*;
import java.awt.event.*;
import java.util.regex.*;
import java.awt.*;
import javax.swing.JTextField;
import javax.swing.ImageIcon;

public class SuperRetail extends JFrame
{
public static void main(String[]args) {

JFrame frame = new JFrame();

JPanel panel1 = new JPanel();
JLabel label1 = new JLabel("Helmet");
ImageIcon myPic1 = new ImageIcon("helmet.jpg");
JButton button1 = new JButton("Add To Cart");

JPanel panel2 = new JPanel();
JLabel label2 = new JLabel("Football");
ImageIcon myPic2 = new ImageIcon("football.jpg");
JButton button2 = new JButton("Add To Cart");

JLabel label3 = new JLabel("Sliotar");
ImageIcon myPic3 = new ImageIcon("sliotar.jpg");
JButton button3 = new JButton("Add To Cart");

JLabel label4 = new JLabel("Hurley");
ImageIcon myPic4 = new ImageIcon("hurley.jpg");
JButton button4 = new JButton("Add To Cart");

JLabel label5 = new JLabel("Gloves");
ImageIcon myPic5 = new ImageIcon("gloves.jpg");
JButton button5 = new JButton("Add To Cart");

JTextField Tf1 = new JTextField();
Tf1.setColumns(20);





button1.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0)
{
Tf1.setText("Helmet added to cart");
}
});


button2.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0)
{
Tf1.setText("Football added to cart");
}
});

button3.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0)
{
Tf1.setText("Sliotar added to cart");
}
});

button4.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0)
{
Tf1.setText("Hurley added to cart");
}
});

button5.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0)
{
Tf1.setText("Gloves added to cart");
}
});


JPanel panel = new JPanel(new BorderLayout(2,2));
panel1 = new JPanel(new GridLayout(3, 2));
panel2 = new JPanel(new GridLayout(3, 2));

panel1.setBackground(Color.RED);
panel1.add(panel1, BorderLayout.WEST);
panel1.add(label1);
panel1.add(button1);


panel.add(panel2, BorderLayout.EAST);
panel2.add(label2);
panel2.add(button2);

panel1.add(label3);
panel1.add(button3);

panel1.add(label4);
panel1.add(button4);

panel1.add(label5);
panel1.add(button5);

panel1.add(Tf1);

frame.add(panel);
frame.add(panel1);
frame.add(panel2);

frame.setVisible(true);

}

}

Here is the FrameViewer Code

import javax.swing.JFrame;

public class SuperRetailViewer
{
public static void main(String[] args)
{
JFrame frame = new SuperRetail();
final int FRAME_WIDTH = 400;
final int FRAME_HEIGHT = 400;
frame.setSize(FRAME_WIDTH, FRAME_HEIGHT);
frame.setTitle("SuperRetail.ie");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
}
 
Thread starter Similar threads Forum Replies Date
B Apps General Discussion 7
C Apps General Discussion 5
S Apps General Discussion 7
S Apps General Discussion 2
Y Apps General Discussion 2
J Apps General Discussion 1
ECHOSIDE Apps General Discussion 3
T Apps General Discussion 1
G Apps General Discussion 3
A Apps General Discussion 3
H Apps General Discussion 1
The Stealthinator Apps General Discussion 3
G Apps General Discussion 3
logox Apps General Discussion 6
zerovit Apps General Discussion 4
CDdude55 Apps General Discussion 16
F Apps General Discussion 7
C Apps General Discussion 5
shuin_exe Apps General Discussion 7
wolfram23 Apps General Discussion 3

ASK THE COMMUNITY