/**
*
*/
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.JTextField;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JLabel;
import java.awt.Color;
public class Artpanel extends JPanel
{
private JLabel label1;
private JLabel label2;
private JLabel label3;
private JTextField input1;
private JTextField input2;
private JButton calculate;
int piece1 = 0;
int piece2 = 0;
/**
* Constructor for objects of class ArtprizePanel
**/
public Artpanel()
{
label1 = new JLabel ("Enter amount of votes for piece 1:");
label2 = new JLabel ("Enter amount of votes for piece 2:");
label3 = new JLabel ("---");
calculate = new JButton ("Calculate");
calculate.addActionListener (new ButtonListener());
input1 = new JTextField (5);
input2 = new JTextField (5);
add (label1);
add (input1);
add (label2);
add (input2);
add (calculate);
add (label3);
setPreferredSize (new Dimension(400, 100));
setBackground (Color.yellow);
}
private class ButtonListener implements ActionListener
{
public void actionPerformed (ActionEvent event)
{
String text = input1.getText();
String text1 = input2.getText();
piece1 = Integer.parseInt (text);
piece2 = Integer.parseInt (text1);
}
}
}
okay here's what i have now. i got the thing to launch, but now i need to figure out how to set an if else statement to determine whether piece 1 or piece 2 is bigger, then display appropriate text in label 3 declaring which one is greater. how would i go about that?