Charles Bell
Posts: 519
Nickname: charles
Registered: Feb, 2002
|
|
Re: Need help with button targets...
|
Posted: Nov 4, 2002 4:34 PM
|
|
import java.awt.*; import java.io.*; import java.applet.*; import java.awt.event.*;
public class StartStopApplet extends Applet implements ActionListener{
private boolean started = false; public void init(){ Button startButton = new Button("Start"); add(startButton); startButton.addActionListener(this); Button stopButton = new Button("Stop"); add(stopButton); stopButton.addActionListener(this); }
public void paint(Graphics g){ if(started){ g.drawString("started",10,10); } else{ g.drawString("stopped",10,10); } }
public void actionPerformed(ActionEvent actionEvent){ String actionCommand = actionEvent.getActionCommand(); if (actionCommand.compareTo("Start") == 0){ started = true; }else if (actionCommand.compareTo("Stop") == 0){ started = false; } repaint(); } }
<html> <head> <title>StartStopApplet</title> </head>
<body> <applet codebase ="." code="StartStopApplet.class" width = "300" height = "100">
</applet>
</body>
</html>
|
|