Рассматривал пример по смещению фигуры
| Код | import javax.swing.*; import java.awt.*; import java.awt.event.*;
public class NewEmpty3 { public static void main(String [] args) { My f=new My(); f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); f.show(); } } class My extends JFrame { private int x1 = 50; public My() { setTitle("123"); setSize(500,500); MyPanel panel = new MyPanel(); Container pane = getContentPane(); pane.add(panel); JToolBar bar = new JToolBar(); JButton b1 = new JButton ("<="); bar.add(b1); b1.addActionListener(new ActionListener() { public void actionPerfomed(ActionEvent event) { x1-=5; repaint(); }
public void actionPerformed(ActionEvent e) { throw new UnsupportedOperationException("Not supported yet."); } }); JButton b2 = new JButton ("=>"); bar.add(b2); b2.addActionListener(new ActionListener() { public void actionPerfomed(ActionEvent event) { x1+=5; repaint(); }
public void actionPerformed(ActionEvent e) { throw new UnsupportedOperationException("Not supported yet."); } }); pane.add(bar,BorderLayout.NORTH); }
class MyPanel extends JPanel { @Override public void paintComponent(Graphics g) { super.paintComponent(g); g.drawOval(x1, 50, 100, 100); } } }
|
Подскажите, почему при нажатии кнопки "<=" или "=>" вместо сдвига выдает ошибку? |