ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
i´ve done a little code now and need some help fixing the errors i get when i try to compile the file.
Here is the code:
Code:
import java.io.*;
import java.awt.*;
import java.awt.event.*;
public class cdapplet extends java.applet.Applet implements ActionListener
public void init ()
{
Color favvobla = new Color(51,102,153;
setBackground(favvobla);
makeTextFields();
makebuttons ();
makeTextArea ();
}
public void makeTextFields()
{
add(new Label ("Artist: "));
name = new TextField(40);
add(name);
}
public void make TextArea()
{
display = new TextArea (50,50);
add(display);
}
public void makeButtons()
{
laggtTillArtist = new Button ("Lägg till Cd");
laggtTillArtist.addActionListener (this);
add(laggTillArtist );
}
here is the errors:
E:\Documents and Settings\Iczer\My Documents\java\bin>javac cdapplet.java
cdapplet.java:5: illegal start of type
public void init()
^
cdapplet.java:19: '{' expected
}
^
error: interface expected here
3 errors
public class cdapplet extends java.applet.Applet implements ActionListener {
and a closing bracket here:
Code:
Color favvobla = new Color(51,102,153);
also it is best to use Capitals for class names so you can easily tell them apart from from variables....
so CdApplet instead of cdapplet
and it looks like you will also need a "}" at the end of the file to close the class cdapplet
EDIT
you also need to do the following
Code:
TextField name = new TextField(40);
....and for same for
TextArea display = new TextArea (50,50);
Button laggtTillAtrist = new Button ("Lägg till Cd");
You will also need the method "actionPerformed" to compile as you implement ActionListener.
Code:
public void actionPerformed(ActionEvent e){
//add code here
}
Thanks for the help, but its more errors that i cant fix now.
Any suggestions?
Code:
Cdapplet.java:10: illegal start of expression
public void actionPerformed(ActionEvent e){
^
Cdapplet.java:34: ';' expected
}
^
Cdapplet.java:4: cdapplet should be declared abstract; it does not define action
Performed(java.awt.event.ActionEvent) in cdapplet
public class cdapplet extends java.applet.Applet implements ActionListener{
^
3 error
I wasnt sure what code to but between
Code:
public void actionPerformed(ActionEvent e){
//add code here
}
So i tried the following
Code:
import java.io.*;
import java.awt.*;
import java.awt.event.*;
public class cdapplet extends java.applet.Applet implements ActionListener{
public void init ()
{
Color favvobla = new Color(51,102,153);
setBackground(favvobla);
public void actionPerformed(ActionEvent e){
makeTextFields();
makebuttons ();
makeTextArea ();
}
public void makeTextFields()
{
add(new Label ("Artist: "));
TextField name = new TextField(40);
add(name);
}
public void make TextArea()
{
TextArea display = new TextArea (50,50);
add(display);
}
public void makeButtons()
{
Button laggtTillAtrist = new Button ("Lägg till Cd");
laggtTillArtist.addActionListener (this);
add(laggTillArtist );
}
}
}
Ah en svensk . Well, your code has more typos than other errors. Remember that Java is a case sensitive language. Button and button and BUTTON are three different variables. I've corrected your code and it should compile and run, but I'm sure the results will not be as pretty as you'd expect:
Code:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class CDApplet extends JApplet implements ActionListener {
public void init () {
Color favvobla = new Color(51,102,153);
setBackground(favvobla);
makeButtons();
makeTextArea();
makeTextFields();
}
public void makeTextFields() {
add(new Label ("Artist: "));
TextField name = new TextField(40);
add(name);
}
public void makeTextArea() {
TextArea display = new TextArea (50,50);
add(display);
}
public void makeButtons() {
Button laggtTillArtist = new Button ("Lägg till Cd");
laggtTillArtist.addActionListener (this);
add(laggtTillArtist);
}
public void actionPerformed(ActionEvent e){
makeTextFields();
makeButtons ();
makeTextArea ();
}
}
You may want to take a look in this thread where I tried to help another member with applet and listeners:
I'd highly recommend you to use an IDE too. It can be as simple as Dr.Java or BlueJ, up to a full-feature one as Eclipse. I recommend this because your coding style has a few problems with indentation that makes it hard to read and will eventually confuse you..
Regards!
Last edited by Mega Man X; 05-15-2006 at 12:16 AM.
Thanks for all the help
I´l try all of this after i installed knoppix.
Im getting an error when i try to install Unbuntu to, its says it can t find /dev/hdd5, i dont have hdd5 :S
any ide´s how to fix it?
i dont know how to get inside the fstab because it says no premission or something to me when i try it :S
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.