I have my code for my program here, and I am having trouble with two different things. First of all I can't get my check box to check when I hit calculate. Any one have any ideas? I have the check boxes in the code but it wont check when I hit calculate to show the largest number.
Second, I have code for if there is a tie but it wont seem to work where ever I put it in my code. here it is!
Does anyone have any suggestins on how to do this?
Code:// String tieMessage = null;
//
// if (piece1 == piece2) {
// if (piece1 == piece3) {
// tieMessage = "It's a tie between pieces 1,2 and 3";
// } else {
// tieMessage = "It's a tie between pieces 1 and 2";
// }
// } else if (piece1 == piece3) {
// tieMessage = "It's a tie between pieces 1 and 3";
// } else if (piece3 == piece2) {
// tieMessage = "It's a tie between pieces 2 and 3";
// }
// if (tieMessage == null) {
Code:import javax.swing.*;
import javax.swing.JOptionPane;
import java.awt.event.*;
import java.awt.*;
import javax.swing.JFrame;
import javax.swing.JCheckBox;
import java.awt.FlowLayout;
class ArtPrizeDemo extends JFrame
{
private JPanel panel; // A holding panel
private JLabel messageLabel1; // A message to the user
private JLabel messageLabel2; // A message to the user
private JLabel messageLabel3; // A message to the user
private JLabel result; // A message to the user
private JTextField piece1; // To hold user input
private JTextField piece2; // To hold user input
private JTextField piece3; // To hold user input
private JCheckBox box1;
private JCheckBox box2;
private JCheckBox box3;
private JButton calculate;
private final int WINDOW_WIDTH = 400; // Window width
private final int WINDOW_HEIGHT = 200; // Window height
int num;
public ArtPrizeDemo()
{
// Set the title.
setTitle("Art Prize");
// Set the size of the window.
setSize(WINDOW_WIDTH, WINDOW_HEIGHT);
// Specify an action for the close button.
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// Build the panel and add it to the frame.
buildPanel();
// Add the panel to the frame's content pane.
add(panel);
// Display the window.
setVisible(true);
}
private void buildPanel()
{
panel= new JPanel();
messageLabel1 = new JLabel("Enter the number of votes for piece 1:");
piece1 = new JTextField(10);
box1 = new JCheckBox(" ");
messageLabel2 = new JLabel("Enter the number of votes for piece 2:");
piece2 = new JTextField(10);
box2 = new JCheckBox(" ");
messageLabel3 = new JLabel("Enter the number of votes for piece 3:");
piece3 = new JTextField(10);
box3 = new JCheckBox(" ");
calculate= new JButton("Calculate");
panel.add(messageLabel1);
panel.add(piece1);
panel.add(box1);
panel.add(messageLabel2);
panel.add(piece2);
panel.add(box2);
panel.add(messageLabel3);
panel.add(piece3);
panel.add(box3);
calculate.addActionListener(new calButtonListener());
panel.add(calculate);
result = new JLabel(" ");
panel.add(result);
}
private class calButtonListener implements ActionListener
{
public void actionPerformed(ActionEvent e)
{
String in;
int p1,p2,p3;
in=piece1.getText();
p1=Integer.parseInt(in);
in=piece2.getText();
p2=Integer.parseInt(in);
in=piece3.getText();
p3=Integer.parseInt(in);
if(p1>p2)
{
if(p1>p3)
{
result.setText("Piece 1 is the winner");
box1.enable(true);
}
else
{
result.setText("Piece 3 is the winner");
box3.enable(true);
}
}
else
{
if(p2>p3)
{
result.setText("Piece 2 is the winner");
box2.enable(true);
}
else
{
result.setText("Piece 3 is the winner");
box3.enable(true);
}
}
class ArtPrize
{
public static void main(String[] args)
{
ArtPrizeDemo frm = new ArtPrizeDemo();
frm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frm.setSize(350,100);
frm.setVisible(true);
}
}

