2015-03-12 2 views
0

Я хочу нарисовать круг и выровнять его по центру, но когда я звоню repaint(), ничего не происходит. Я пробовал почти все, я изменил макеты, выравнивания, но всегда то же самое. Это мой код:repaint() не работает

public class Frame extends JFrame { 

    JButton button,dugme; 
    JLabel lab; 

    public Frame(){ 
     setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); 
     setSize(480,320); 
     setResizable(false); 
     setLocationRelativeTo(null); 
     setLayout(new FlowLayout()); 
     setVisible(true); 

     button = new JButton("Klikni me"); 
     button.setSize(75,75); 
     add(button); 
     button.setHorizontalAlignment(SwingConstants.RIGHT); 

     dugme= new JButton("Klikni opet"); 
     dugme.setSize(75,75); 
     add(dugme); 
     dugme.setHorizontalAlignment(SwingConstants.LEFT); 

     lab = new JLabel("Ovde je tekst koji se menja"); 
     add(lab); 
     lab.setHorizontalAlignment(SwingConstants.CENTER); 
     Handler handler = new Handler(); 
     Handler1 handler1= new Handler1(); 
     repaint(); 

     button.addActionListener(handler); 
     dugme.addActionListener(handler1); 
    } 

    public void paintComponent(Graphics g){ 
     super.paintComponents(g); 
     g.fillOval(30, 30, 60, 75); 
    } 

    public class Handler implements ActionListener{ 
     public void actionPerformed(ActionEvent e){ 
      repaint(); 
      lab.setText("New text"); 
     } 
    } 

    public class Handler1 implements ActionListener{ 
     public void actionPerformed(ActionEvent e){ 
      lab.setText("Same text again "); 
       repaint(); 
     } 
    } 
} 

ответ

3
public void paintComponent(Graphics g){ 
    super.paintComponents(g); 

Перерывы краска цепи, она должна быть:

public void paintComponent(Graphics g){ 
    super.paintComponent(g); // no S in method name.. 
+1

Хорошо, спасибо на советы. – Djehenghizz

 Смежные вопросы

  • Нет связанных вопросов^_^