How to set size of applet?

烂漫一生 提交于 2019-12-02 06:56:02

问题


I have written a little test applet and start the applet via Eclipse appletviewer. I have noted tag at the begginig of the code, but appletviewer doesn't see it. It starts the applet in standart window with the same size every time. I use JDK 1.7, Eclipse Kepler

import java.awt.Container;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JApplet;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

/*<applet code="TestApplet" width=200 height=40>
</applet>
*/
public class TestApplet extends JApplet{
    private Container cp;
    private JPanel mainPanel, testPanel1;
    private JLabel testLabel1 = new JLabel("Test1"),
                testLabel2 = new JLabel("Test2");
    private JTextField testTextField1 = new JTextField(),
            testTextField2 = new JTextField();
    private JButton testButton1 = new JButton("TestButton1"),
            testButton2 = new JButton("TestButton2");
    public void init(){
        cp = getContentPane();
        testPanel1 = new JPanel(new GridLayout(3,1));
        cp.add(testPanel1);
        testPanel1.add(testLabel1);
        testPanel1.add(testTextField1);
        testPanel1.add(testButton1);
    }

    public void start(){
    }

    public void stop(){

    }

    public void destroy(){

    }
}

How can I change size of the applet window when I start it using Eclipse?


回答1:


You can change it in Run Configurations in Eclipse:

Run -> Run Configurations -> Java Applet -> New Configuration. the default size can be changed in the Parameters tab.

Note that this is only for testing and the actual applet your user sees is depends on how the applet is launched for them (Which is done typically via a <applet>, <object> or <embed> tags in a webpage. all of these tags support size attributes.)



来源:https://stackoverflow.com/questions/23365183/how-to-set-size-of-applet

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!