如何设置小程序的大小?

2023-12-02

我编写了一个小测试小程序并通过 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(){

    }
}

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


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

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

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

enter image description here

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

如何设置小程序的大小? 的相关文章

随机推荐