i am having trouble putting together all the pieces of the puzzle to work together in harmony. My final project is simple,i have a jlabel with the question of how much does your dog weigh, I have a button and a jtextfield, the user enters the amount of there dog, and the program will tell them what size dog there's is... ( e.g. small, large )
I cant figure out what works with what, i have tried things from if statements but they don't work with strings, to get source, but i have a problem with errors... What should i use to get the outcome i want...? here is my starting code
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
public class Final2 extends JFrame implements ActionListener
{
JLabel question = new JLabel("How much does your dog weigh?");
Font bigFont = new Font("Arial", Font.BOLD, 16);
JTextField answer = new JTextField(10);
JButton pressMe = new JButton("press me");
JLabel greeting = new JLabel("");
final int WIDTH = 300;
final int HEIGHT = 300;
Container con = getContentPane();
public Final2()
{
super("Final Project");
setSize(WIDTH,HEIGHT);
setLayout(new FlowLayout());
question.setFont(bigFont);
greeting.setFont(bigFont);
greeting.setForeground(Color.WHITE);
question.setForeground(Color.WHITE);
add(question);
add(answer);
add(pressMe);
add(greeting);
pressMe.addActionListener(this);
setVisible(true);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
con.setBackground(Color.BLUE);
}
public void actionPerformed(ActionEvent e)
{
String breed = answer.getText();
String greet = "Your dog is of " + breed + " breed.";
greeting.setText(greet);
}
public static void main(String[] args)
{
Final2 frame = new Final2();
}
}