Click here to Skip to main content
15,897,704 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have no errors, only a warning on the class. It insists on not initializing though and I have no idea what's wrong. Can someone please help me?


Java
package com.saizen;

import java.applet.Applet;
import java.awt.Button;
import java.awt.TextField;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class T3xt extends Applet implements ActionListener {

	TextField text1;
	Button button1, button2;

	public void init(){
		add(text1);
		add(button1);
		add(button2);
		text1 = new TextField(20);
		button1 = new Button("first");
		button2 = new Button("second");
		button1.addActionListener(this);
		button2.addActionListener(this);
	}

	public void actionPerformed(ActionEvent e) {
		if (e.getSource() == button1){
			text1.setText("Hello!");
		}
		if (e.getSource() == button2){
			text1.setText("How are you today?");
		}
	}


}
Posted
Updated 13-Feb-12 11:52am
v2
Comments
Sergey Alexandrovich Kryukov 13-Feb-12 17:53pm    
Please use "pre" tags the way I did (see "Improve question" to see how it should be formatted, I did it for you).
--SA
Mein Nam 13-Feb-12 18:02pm    
Really? That's what help you give me?

1 solution

just exchange sequence


Java
add(text1);
        
        text1 = new TextField(20);
        button1 = new Button("first");
        button2 = new Button("second");
        add(text1);
		add(button1);
		add(button2);
		text1 = new TextField(20);
		button1 = new Button("first");
		button2 = new Button("second");


let me know what happen.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900