Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JButton disappears when resize

anyone know or have an idea as to why my button disappears after i resize the applet?

this is my code:


import java.awt.event.*;
import javax.swing.*;
import acm.program.*;

public class button extends ConsoleProgram {

    public void init(){

        hiButton = new JButton("hi");
        add(hiButton, SOUTH);
        addActionListeners();


    }

    public   void actionPerformed(ActionEvent e){
        if(hiButton == e.getSource()){
           println("hello") ;
        }

    }
private JButton hiButton;


}

like image 864
Elias Sanchez Avatar asked Sep 01 '12 23:09

Elias Sanchez


1 Answers

I'm not sure if it is a good Idea to redefine the init-method. When I have a look at http://jtf.acm.org/javadoc/student/acm/program/ConsoleProgram.html I would expect that you have implement only the run-method. Overriding init without calling super.init() Looks strange to me.

Maybe I would be better to derive from JApplet directly for your first steps in Applet programming.

like image 56
Franz Fischer Avatar answered Oct 10 '22 23:10

Franz Fischer