사각형의 색상을 변경하는 방법은 무엇입니까? 나는 그것을 노란 색으로 바꾸고 싶다. 안에 g.setColor(Color.YELLOW);
을 추가했지만 사각형의 색상은 여전히 동일하게 유지됩니다. 누군가 내가 뭘 잘못했는지 말해 줄 수 있니?Java GUI에서 직사각형 색상 변경
public class SelectSeat {
static JFrame frame;
public JPanel createContentPane() throws IOException
{
JPanel totalGUI = new JPanel();
RectDraw rect= new RectDraw();
rect.setPreferredSize(new Dimension(330,35)); //for size
totalGUI.setLayout(null);
totalGUI.setBackground(Color.WHITE);
totalGUI.add(rect);
Dimension d = rect.getPreferredSize();
rect.setBounds(100, 20, d.width, d.height); // for location
return totalGUI;
}
void setVisible(boolean b) {
// TODO Auto-generated method stub
}
static void createAndShowGUI() throws IOException
{
JFrame.setDefaultLookAndFeelDecorated(true);
frame = new JFrame("Seat Selection");
//Create and set up the content pane.
SelectSeat demo = new SelectSeat();
frame.setContentPane(demo.createContentPane());
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(535, 520);
frame.setLocation(500,220);
frame.setVisible(true);
}
private static class RectDraw extends JPanel
{
protected void paintComponent(Graphics g) {
super.paintComponent(g);
g.setColor(Color.BLUE);
g.drawString("Movie Sceen", 130, 20);
}
}
}
'g.setColor (Color.YELLOW);를 추가했습니다. '게시 된 코드에서 해당 호출이 표시되지 않습니다. 통화 후 직사각형을 채우시겠습니까? – copeg