The Artima Developer Community
Sponsored Link

Java Answers Forum
Need help with button targets...

1 reply on 1 page. Most recent reply: Nov 4, 2002 4:34 PM by Charles Bell

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
Taylor Smith

Posts: 1
Nickname: darkhammer
Registered: Nov, 2002

Need help with button targets... Posted: Nov 1, 2002 12:34 PM
Reply to this message Reply
Advertisement
I am a student, and just started using applets. I can do everything I need to except for this: I can't make my button close the program. I want to make it so that when you click the button with the mouse it closes the program, but when I try it it says it can't convert 'Applet1' (my applet name) into 'void', the return type.

What I'm trying to do is make the button rerout the user to a stop command, but the command is under "public void". It does not like "void". What return type should I put?


Charles Bell

Posts: 519
Nickname: charles
Registered: Feb, 2002

Re: Need help with button targets... Posted: Nov 4, 2002 4:34 PM
Reply to this message Reply

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>

Flat View: This topic has 1 reply on 1 page
Topic: what about JAVA Previous Topic   Next Topic Topic: hashtables

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use