3 Replies - 759 Views - Last Post: 16 March 2011 - 04:12 AM Rate Topic: -----

#1 denisonjava  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 10
  • Joined: 11-March 11

Applet problem (using TextPad 4.7)

Posted 15 March 2011 - 04:06 AM

I'm not sure what the problem is, when I compile it I am getting compiler errors and when I run I get en error saying it cannot find the .class file
Here is the code:
import java.awt.applet.*;
import java.awt.*;
import java.awt.event.*;

public class Greet8 extends Applet implements ActionListener {

	Label greeting = new Label("Hello. Who are you?");
	Font bigFont = new Font("TimesRoman",Fonr.ITALIC,24);
	Button pressMe = new Button("Press Me");
	TextField answer = new TextField("",30);

	public void init() {

	greeting.setFont(bigFont);
	add(greeting);
	add(answer);
	add(pressMe);
	answer.requestFocus();
	pressMe.addActionListener(this);
	answer.addActionListener(this);
	}

public void actionPerformed(ActionEvent thisEvent) {

	String name = answer.getText();
	Label personalGreeting = new Label("");
	personalGreeting.setText("Hi there "+name+". How are you?");
	add(personalGreeting);

	invalidate();
	validate();
	remove(answer);
	remove(pressMe);
	}
}


Thanks,
Denis

Is This A Good Question/Topic? 0
  • +

Replies To: Applet problem (using TextPad 4.7)

#2 macosxnerd101  Icon User is online

  • Self-Trained Economist
  • member icon




Reputation: 10486
  • View blog
  • Posts: 38,857
  • Joined: 27-December 08

Re: Applet problem (using TextPad 4.7)

Posted 15 March 2011 - 06:34 AM

First, use the more modern Swing Components and JComponents like JApplet, JLabel, etc., rather than the antiquated AWT Components.

Second, what specific problems or errors are you encountering? Post the errors as they appear on your compiler.
Was This Post Helpful? 0
  • +
  • -

#3 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8329
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: Applet problem (using TextPad 4.7)

Posted 15 March 2011 - 07:22 PM

View Postdenisonjava, on 15 March 2011 - 06:06 AM, said:

I'm not sure what the problem is, when I compile it I am getting compiler errors and when I run I get en error saying it cannot find the .class file

If the compiler generates errors no .class file are generated so useless to try to run it :)

You have bad import and Font is Font not Fonr

// applet is not part of awt import java.awt.applet.*;
import java.applet.Applet;  // <--- so this is the good import
import java.awt.*;
import java.awt.event.*;

public class Greet8 extends Applet implements ActionListener {

	Label greeting = new Label("Hello. Who are you?");
	Font bigFont = new Font("TimesRoman",Fonr.ITALIC,24);     // Font not Fonr
	Button pressMe = new Button("Press Me");
	TextField answer = new TextField("",30);

	public void init() {

	greeting.setFont(bigFont);
	add(greeting);
	add(answer);
	add(pressMe);
	answer.requestFocus();
	pressMe.addActionListener(this);
	answer.addActionListener(this);
	}

public void actionPerformed(ActionEvent thisEvent) {

	String name = answer.getText();
	Label personalGreeting = new Label("");
	personalGreeting.setText("Hi there "+name+". How are you?");
	add(personalGreeting);

	invalidate();
	validate();
	remove(answer);
	remove(pressMe);
	}
}



And as macosxnerd101 suggested switch to Swing
Was This Post Helpful? 1
  • +
  • -

#4 denisonjava  Icon User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 10
  • Joined: 11-March 11

Re: Applet problem (using TextPad 4.7)

Posted 16 March 2011 - 04:12 AM

hmmm I never noticed those mistakes, I guess I was staring at it too long, and the reason I'm using awt is because it is for class and we're starting off with it.

*and thank you
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1