Hey guys ik heb het volgende in elkaar gezet, maar het werkt niet. Kunnen jullie mij mischien helpen?
/**
* <p>Title: Timer </p>
* <p>Description: Timer</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.awt.Graphics.*;
public class timer extends JFrame implements ActionListener
{
public static void main(String[] args);
{
//Het aanmaken van drie buttons
private JButton start = new JButton("start");
private JButton stop = new JButton("stop");
private JButton reset = new JButton("reset");
//Aanmaken van de variabelen voor het tellen
double tStart = 0;
double tEind = 0;
//voorbereiden en maken van de eerste input
String output = " " + tEind;
JLabel result = new JLabel(output);
//constructor
public timer()
{
//Bouwen van het scherm en Layout instellen
Container container = getContentPane();
container.setLayout(newBorderLayout());
//aanmaken van twee panelen, waar de inhoud in gaat komen.
JPanel p1 = new JPanel();
JPanel p2 = new JPanel();
//panelen instellen op flowlayout.
p1.setLayout(new FlowLayout());
p2.setLayout(new FlowLayout());
// Een JTextfield oid toevoegen aan p1
p1.add(result);
// toevoegingen aan p2
p2.add(start);
// p1 en p2 toevoegen aan container
container.add(p1, BorderLayout.NORTH);
container.add(p2, BorderLayout.SOUTH);
//ActionListener koppelen aan de knoppen.
start.addActionListener(this);
}
public static void main(String[] args)
{
//Standaard stuk grafische applicatie bouwen!
timer frame = new timer();
frame.setTitle("PrikKlok");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(400, 200);
frame.setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
if (e.getSource() == start)
{
tStart = System.currentTimeMillis();
repaint();
}
if (e.getSource() == stop)
{
tEind = (System.currentTimeMillis() - tStart)/1000;
result.setText(output);//output naar het scherm zetten.
repaint();
}
}
}
/**
* <p>Title: Timer </p>
* <p>Description: Timer</p>
* <p>Company: </p>
* @author not attributable
* @version 1.0
*/
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
import java.awt.Graphics.*;
public class timer extends JFrame implements ActionListener
{
public static void main(String[] args);
{
//Het aanmaken van drie buttons
private JButton start = new JButton("start");
private JButton stop = new JButton("stop");
private JButton reset = new JButton("reset");
//Aanmaken van de variabelen voor het tellen
double tStart = 0;
double tEind = 0;
//voorbereiden en maken van de eerste input
String output = " " + tEind;
JLabel result = new JLabel(output);
//constructor
public timer()
{
//Bouwen van het scherm en Layout instellen
Container container = getContentPane();
container.setLayout(newBorderLayout());
//aanmaken van twee panelen, waar de inhoud in gaat komen.
JPanel p1 = new JPanel();
JPanel p2 = new JPanel();
//panelen instellen op flowlayout.
p1.setLayout(new FlowLayout());
p2.setLayout(new FlowLayout());
// Een JTextfield oid toevoegen aan p1
p1.add(result);
// toevoegingen aan p2
p2.add(start);
// p1 en p2 toevoegen aan container
container.add(p1, BorderLayout.NORTH);
container.add(p2, BorderLayout.SOUTH);
//ActionListener koppelen aan de knoppen.
start.addActionListener(this);
}
public static void main(String[] args)
{
//Standaard stuk grafische applicatie bouwen!
timer frame = new timer();
frame.setTitle("PrikKlok");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setSize(400, 200);
frame.setVisible(true);
}
public void actionPerformed(ActionEvent e)
{
if (e.getSource() == start)
{
tStart = System.currentTimeMillis();
repaint();
}
if (e.getSource() == stop)
{
tEind = (System.currentTimeMillis() - tStart)/1000;
result.setText(output);//output naar het scherm zetten.
repaint();
}
}
}