luboldja
11-14-2009, 07:16 PM
Yea, here is the code i am working on atm, and i am even more stuck now than ever.
final JLabel car = new JLabel();
car.setIcon(new ImageIcon("Images/car.png"));
car.setBounds(1,150,80,30);
final JTextField txtColor = new JTextField();
txtColor.setBounds(1, 100, 30, 20);
JButton butColor = new JButton("Set Color");
butColor.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
objCar.setColor(txtColor.getText());
if(getText = "red"){
car.setIcon(new ImageIcon("Images/redCar.png"));
}
}
}
);
What this is going to look like is a text field and to the right a button that says Set Color. Im attempting to make a variable for the color of the car in GameGui, because i dont know how to do it in my clsAutos, that is equal to whatever is entered into the text. And then, i have about 5 different pictures with the same car in different colors. I will do like, 5 if/else if statements and tell them something like (please enter one of the following colors: black/red/green/yelloe/blue) and then car.setIcon(new ImageIcon("Images/greenCar.png)
is an example if they enter green. I know how to write ALL of the code, exept making the variable whatever was entered into the text field. Any ideas?
final JLabel car = new JLabel();
car.setIcon(new ImageIcon("Images/car.png"));
car.setBounds(1,150,80,30);
final JTextField txtColor = new JTextField();
txtColor.setBounds(1, 100, 30, 20);
JButton butColor = new JButton("Set Color");
butColor.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
objCar.setColor(txtColor.getText());
if(getText = "red"){
car.setIcon(new ImageIcon("Images/redCar.png"));
}
}
}
);
What this is going to look like is a text field and to the right a button that says Set Color. Im attempting to make a variable for the color of the car in GameGui, because i dont know how to do it in my clsAutos, that is equal to whatever is entered into the text. And then, i have about 5 different pictures with the same car in different colors. I will do like, 5 if/else if statements and tell them something like (please enter one of the following colors: black/red/green/yelloe/blue) and then car.setIcon(new ImageIcon("Images/greenCar.png)
is an example if they enter green. I know how to write ALL of the code, exept making the variable whatever was entered into the text field. Any ideas?