: : Changed the code to this i only see a button now.
: : Is there something special i have to write in the JApplet? Note that
: : the source code for the JApplet is rather long but I'll post it if
: : its necessary.
: :
: : public static void main(String arg[]){
: : JFrame f=new JFrame();
: : f.setSize(1200,700);
: : f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
: : f.setVisible(true);
: : f.setLayout(new GridLayout(2,2));
: : SSF ssf=new SSF();
: : ssf.setSize(1200,700);
: :
: : f.add(ssf);
: : f.add(new JButton("Yoho"));
: : }: : A side question how to make a pointer in java?
: : I have a int shipx;
: : that i want to give to x;
: : and i want x to point to shipx and this change it value whenever
: : shipx does. Thanks for the help.
:
: Change the add() code to include the constraints of where the
: component needs to be placed. Thus:
:
:
: f.add(ssf, BorderLayout.CENTER);
:
:
: To have the applet fill the frame. You don't need any additional
: code changes in the applet.
:
: There are no pointers in Java. It is possible to encapsule the int
: value into an Integer object. Then you can reference that object,
: because objects are accessed by reference not by value.
:
Here's a working example of a JApplet in a JFrame:
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import java.awt.HeadlessException;
import javax.swing.JApplet;
import javax.swing.JButton;
import javax.swing.JFrame;
public class FrameTest extends JFrame {
public FrameTest() throws HeadlessException {
super();
Test t = new Test();
t.init();
add(t, BorderLayout.CENTER);
}
public static void main(String[] args) {
FrameTest ft = new FrameTest();
ft.setSize(800, 600);
ft.setVisible(true);
}
}
class Test extends JApplet {
@Override
public void init() {
super.init();
setLayout(new FlowLayout());
add(new JButton("Hello World"));
}
}