Java 如何设置小程序的大小?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23365183/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-13 22:15:19  来源:igfitidea点击:

How to set size of applet?

javaeclipseappletjappletappletviewer

提问by Buralek

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

我已经编写了一个小测试小程序并通过 Eclipse appletviewer 启动小程序。我在代码的开始处注意到了标记,但 appletviewer 没有看到它。它每次都在标准窗口中以相同的大小启动小程序。我使用 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?

使用 Eclipse 启动小程序窗口时,如何更改小程序窗口的大小?

采纳答案by Nivas

You can change it in Run Configurations in Eclipse:

您可以在 Eclipse 中的运行配置中更改它:

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

Run -> Run Configurations -> Java Applet -> New Configuration. 可以在“参数”选项卡中更改默认大小。

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.)

请注意,这仅用于测试,您的用户看到的实际小程序取决于为他们启动小程序的方式(通常通过网页中的<applet>,<object><embed>标签完成。所有这些标签都支持大小属性。)

enter image description here

在此处输入图片说明