Code: Select all
import javax.swing.*;
import java.awt.event.*;
import java.awt.*;
public class LoopPanel extends JFrame implements ActionListener {
private wine dionysus;
private book stine;
private cheese cheddar;
private int button_count = 0;
public final static boolean RIGHT_TO_LEFT = false;
private JFrame frame;
/*Wine*/
private JButton wineButt;
private JLabel [] wine_Label;
private JLabel [] wine_Label_copy;
private JLabel [] wine_Output;
private JTextField [] wine_Field;
/*book*/
private JButton bookButt;
private JLabel [] book_Label;
private JLabel [] book_Label_copy;
private JLabel [] book_Output;
private JTextField [] book_Field;
/*cheese*/
private JButton cheeseButt;
private JLabel [] cheese_Label;
private JLabel [] cheese_Label_copy;
private JLabel [] cheese_Output;
private JTextField [] cheese_Field;
////////////MAIN////////////////////////
public static void main(String[] args) {
LoopPanel tpo = new LoopPanel(); // create 'the program object'
tpo.addWindowListener(new WindowAdapter() { // this exits the program when X box clicked
public void windowClosing(WindowEvent e) {
System.exit(0);
}
});}
////////////CONSTRUCTOR/////////////////////
public LoopPanel () {
dionysus = new wine();
stine = new book();
cheddar = new cheese();
wine_Output = new JLabel[7];
wine_Field = new JTextField[3];
wine_Label = new JLabel[3];
wine_Label[0]= new JLabel("Name of the Wine:");
wine_Label[1] = new JLabel("Origin of the Wine:");
wine_Label[2] = new JLabel("Alcohol Content:");
wine_Label_copy = wine_Label.clone();
book_Output = new JLabel[7];
book_Field = new JTextField[3];
book_Label = new JLabel[3];
book_Label[0] =new JLabel("Author of Book:");
book_Label[1] = new JLabel("Title of the Book:");
book_Label[2] = new JLabel("Number of Pages:");
book_Label_copy = book_Label.clone();
cheese_Output = new JLabel[7];
cheese_Field = new JTextField[3];
cheese_Label = new JLabel[3];
cheese_Label[0] = new JLabel("Type of Cheese:");
cheese_Label[1] = new JLabel("Color of the Cheese:");
cheese_Label[2] = new JLabel("Weight of the Cheese:");
cheese_Label_copy = cheese_Label.clone();
frame = new JFrame("testing");
addComponentsToPane(frame.getContentPane());
shoutpane (frame.getContentPane());
frame.pack();
frame.setVisible(true);
}
public void shoutpane (Container pane){
/*if (RIGHT_TO_LEFT) {
pane.setComponentOrientation(
ComponentOrientation.RIGHT_TO_LEFT);
}
setLayout(new GridLayout(0,7));*/
shout_panelize(wine_Output, wine_Label_copy, pane);
shout_panelize(book_Output, book_Label_copy, pane);
shout_panelize(cheese_Output, cheese_Label_copy, pane);
}
public void shout_panelize(JLabel[] output, JLabel[] label, Container pane){
int label_count = label.length;
int output_count = output.length;
int i = 0;
while (i < label_count){
//label[i] = new JLabel();
//output[i] = new JLabel();
//if (i > output.length){
label[i] = new JLabel();
output[i] = new JLabel();
pane.add(label[i]);
pane.add(output[i]);
/* }
else{
output[i] = new JLabel();
pane.add(label[i]);
pane.add(output[i]);
}*/
i++;
}
}
public void addComponentsToPane(Container pane) {
if (RIGHT_TO_LEFT) {
pane.setComponentOrientation(
ComponentOrientation.RIGHT_TO_LEFT);
}
pane.setLayout(new GridLayout(0,7));
panelize (wine_Label, wine_Field, wineButt, pane);
panelize (book_Label, book_Field, bookButt, pane);
panelize (cheese_Label, cheese_Field, cheeseButt, pane);
}
public void panelize (JLabel[] label , JTextField[] field, JButton silly, Container pane){
int label_count = label.length;
//int output_count = output.length;
// int field_count = field.length;
int i = 0;
while (i < label_count){
//label[i] = new JLabel();
field[i] = new JTextField("",7);
pane.add(label[i]);
pane.add(field[i]);
i++;
}
silly= new JButton(String.valueOf(button_count));
silly.setActionCommand(String.valueOf(button_count));
//silly.setName();
button_count++;
silly.addActionListener(this);
pane.add(silly);
}
public void actionPerformed(ActionEvent e) {
String s = e.getActionCommand();
String newtext;
int ant;
double whopper;
//System.out.println(e.getSource());
if(e.getActionCommand() == String.valueOf(0) || e.getSource() == wineButt){
Toolkit.getDefaultToolkit().beep();
System.out.println(e.getSource());
/*wine name*/
//newtext = ;
dionysus.setWine_name(wine_Field[0].getText());
wine_Output[0].setText(dionysus.getWine_name());
/*wine origin*/
//newtext = wine_Field[1].getText();
dionysus.setWine_origin(wine_Field[0].getText());
wine_Output[1].setText(dionysus.getWine_origin());
/*alcohol content*//*
whopper = Double.parseDouble(wine_Field[2].getText());
dionysus.setAlcohol_content(whopper);
wine_Output[2].toString().setText(dionysus.toString().getAlcohol_content());*/
}
}
}
Sorry, it is a very big snippet but I'm not sure as to why my actionPerformed will not work. I do have three other classes with get and set methods but that is all those classes contain with an empty constructor.
the problem I'm having is to click on a button ( the first button in the snippet), work, or do something. Any help is appreciated and a thanks in advance.