Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Applets - beginner  RSS feed

 
Mike Meakin
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, I am just begining to learn about applets and I have to draw a rectangle, but I am getting trouble even trying to draw the first line. Heres the error I get:
"Applet1.java": Error #: 200 : ';' expected at line 12, column 17

Heres he code:

package untitled4;

import java.awt.*;
import java.awt.event.*;
import java.applet.*;

public class Applet1 extends Applet {
boolean isStandalone = false;
public void paint(Graphics a)
//this method displays the applet using the Graphics class to draw it.
{
void drawLine(int x0, int y0, int x1, int y1);
}
/**Get a parameter value*/
public String getParameter(String key, String def) {
return isStandalone ? System.getProperty(key, def) :
(getParameter(key) != null ? getParameter(key) : def);
}

/**Construct the applet*/
public Applet1() {
}
/**Initialize the applet*/
public void init() {
try {
jbInit();
}
catch(Exception e) {
e.printStackTrace();
}
}
/**Component initialization*/
private void jbInit() throws Exception {
}
/**Get Applet information*/
public String getAppletInfo() {
return "Applet Information";
}
/**Get parameter info*/
public String[][] getParameterInfo() {
return null;
}
/**Main method*/
public static void main(String[] args) {
Applet1 applet = new Applet1();
applet.isStandalone = true;
Frame frame;
frame = new Frame() {
protected void processWindowEvent(WindowEvent e) {
super.processWindowEvent(e);
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
System.exit(0);
}
}
public synchronized void setTitle(String title) {
super.setTitle(title);
enableEvents(AWTEvent.WINDOW_EVENT_MASK);
}
};
frame.setTitle("Applet Frame");
frame.add(applet, BorderLayout.CENTER);
applet.init();
applet.start();
frame.setSize(500,350);
Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
frame.setLocation((d.width - frame.getSize().width) / 2, (d.height - frame.getSize().height) / 2);
frame.setVisible(true);
}
}
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In paint(), you've got the following line:

void drawLine(int x0, int y0, int x1, int y1);

which looks like the declaration of an interface method -- it's got a return type, and argument types... it's not a call to a method, which would be the only value way to use anything like this inside the paint() method (or any method).

drawLine() is a method of the Graphics class, and you have to supply numbers as arguments. You could replace that line with something like

a.drawLine(10, 10, 100, 100);

But in any case, it sounds like you're not just starting to learn about Applets, but actually just starting to learn about Java. You're going to need a book; you might try Head First Java as a gentle introduction.
 
Mike Meakin
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes Iam supposed to use the line:
void drawLine(int x0, int y0, int x1, int y1);
As I am instructed to do in my Text book, but for some reason it doesn't work ?
I maybe wrong so I'll try your advice and see if it works, Thanks!
[ April 17, 2005: Message edited by: Michael Munro ]
 
Mike Meakin
Ranch Hand
Posts: 88
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey you were Right it works now!
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!