Ciao a tutti. Ho provato già a fare una ricerca su internet e sul forum ma non sono riuscito a capire come funziona questa classe... devo svolgere un esecizio, ogni secondo devo disegnare su un JPanel delle linee casuali. Il problema sta nell'utilizzare questo Timer(). Ho provato a scrivere:
Ma mi da questo errore: "error: Class names, 'Time', are only accepted if annotation processing is explicititly requested"codice:import java.awt.*; import java.awt.event.*; import java.util.Random; import javax.swing.*; public class Time extends JPanel implements ActionListener { public Time() { Timer timer = new Timer(1000,this); timer.start(); } public void actionPerformed(ActionEvent event) { repaint(); } public void paintComponent(Graphics g) { super.paintComponent(g); Random random = new Random(); for (int i=0;i<100;i++) { g.drawLine(random.nextInt(400),random.nextInt(350),random.nextInt(400),random.nextInt(350)); } } public static void main(String[] args) { Time panel = new Time(); JFrame frame = new JFrame("Timer"); frame.setSize(400,350); frame.setLocationRelativeTo(null); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.add(panel); frame.setVisible(true); } }
Non so come fare per risolvere e non so bene come utilizzare la classe Timer(), percui l'ho fatta a testa mia... qualcuno può chiarirmi le idee? ^^

Rispondi quotando