nvidia
02-05-2007, 01:46 PM
Hi i have panel with the following code:
public TextField textField;
public String labelText = ("Enter no.of ovals");
public String selection = ("Make Selection");
public Label enter = new Label(labelText, Label.LEFT);
public Label shapeSelection = new Label(selection, Label.LEFT);
public Panel top = new Panel();
MainWindow()
{
top.add(shapeSelection);
top.add(textField);
add(top, BorderLayout.NORTH);
}
public void paint(Graphics gc)
{
if(m_bSelectOval)
{
JOptionPane.showMessageDialog(this, "inside graphics for oval.");
top.setBackground(java.awt.Color.green);
top.add(enter);
add(top, BorderLayout.NORTH);
repaint();
m_bSelectOval = false;
}
}
public void itemStateChanged(ItemEvent evt)
{
if ( evt.getItemSelectable() == m_oval )
{
JOptionPane.showMessageDialog(this, "U selected the oval radio button.");
repaint();
m_bSelectOval = true;
}
}
When i run the code i see the make selection and the text field. When i click on the radio button it goes into my into my item statched function which displays the message, u have selected oval radio button which is fine and oval is set to true. After it is set true i see the second message which is fine, and the north panel is changed to color, green. However, i cannot see my first label change to (enter) which has the message "enter number of ovals:"
My question is therefore why does only the north panel change colour but not ALSO have the new message??
public TextField textField;
public String labelText = ("Enter no.of ovals");
public String selection = ("Make Selection");
public Label enter = new Label(labelText, Label.LEFT);
public Label shapeSelection = new Label(selection, Label.LEFT);
public Panel top = new Panel();
MainWindow()
{
top.add(shapeSelection);
top.add(textField);
add(top, BorderLayout.NORTH);
}
public void paint(Graphics gc)
{
if(m_bSelectOval)
{
JOptionPane.showMessageDialog(this, "inside graphics for oval.");
top.setBackground(java.awt.Color.green);
top.add(enter);
add(top, BorderLayout.NORTH);
repaint();
m_bSelectOval = false;
}
}
public void itemStateChanged(ItemEvent evt)
{
if ( evt.getItemSelectable() == m_oval )
{
JOptionPane.showMessageDialog(this, "U selected the oval radio button.");
repaint();
m_bSelectOval = true;
}
}
When i run the code i see the make selection and the text field. When i click on the radio button it goes into my into my item statched function which displays the message, u have selected oval radio button which is fine and oval is set to true. After it is set true i see the second message which is fine, and the north panel is changed to color, green. However, i cannot see my first label change to (enter) which has the message "enter number of ovals:"
My question is therefore why does only the north panel change colour but not ALSO have the new message??