小程序未显示完整

2024-02-01

我刚刚创建了一个小程序

public class HomeApplet extends JApplet {

    private static final long serialVersionUID = -7650916407386219367L;

    //Called when this applet is loaded into the browser.
    public void init() {
        //Execute a job on the event-dispatching thread; creating this applet's GUI.
//      setSize(400, 400);
        try {
            SwingUtilities.invokeAndWait(new Runnable() {
                public void run() {
                    createGUI();
                }
            });
        } catch (Exception e) { 
            System.err.println("createGUI didn't complete successfully");
        }
    }

    private void createGUI() {
        RconSection rconSection = new RconSection();
        rconSection.setOpaque(true); 

//      CommandArea commandArea = new CommandArea();
//      commandArea.setOpaque(true); 

        JTabbedPane tabbedPane = new JTabbedPane();
//      tabbedPane.setSize(400, 400);
        tabbedPane.addTab("Rcon Details", rconSection);
//      tabbedPane.addTab("Commad Area", commandArea); 


        setContentPane(tabbedPane);       
    }
}

其中第一个选项卡是:

package com.rcon;

import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

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

import com.Bean.RconBean;
import com.util.Utility;

public class RconSection extends JPanel implements ActionListener{
    /**
     * 
     */
    private static final long serialVersionUID = -9021500288377975786L;
    private static String TEST_COMMAND = "test";
    private static String CLEAR_COMMAND = "clear";
    private static JTextField ipText = new JTextField();
    private static JTextField portText = new JTextField();
    private static JTextField rPassText = new JTextField();
    //      private DynamicTree treePanel;

    public RconSection() {
//      super(new BorderLayout());
        JLabel ip = new JLabel("IP");
        JLabel port = new JLabel("Port");
        JLabel rPass = new JLabel("Rcon Password");

        JButton testButton = new JButton("Test");
        testButton.setActionCommand(TEST_COMMAND);
        testButton.addActionListener(this);

        JButton clearButton = new JButton("Clear");
        clearButton.setActionCommand(CLEAR_COMMAND);
        clearButton.addActionListener(this);

        JPanel panel = new JPanel(new GridLayout(3,2));
        panel.add(ip);
        panel.add(ipText);
        panel.add(port);
        panel.add(portText);
        panel.add(rPass);
        panel.add(rPassText);

        JPanel panel1 = new JPanel(new GridLayout(1,3));
        panel1.add(testButton);
        panel1.add(clearButton);

        add(panel);
        add(panel1);
//      add(panel, BorderLayout.NORTH);
//      add(panel1, BorderLayout.SOUTH);
    }

    @Override
    public void actionPerformed(ActionEvent arg0) {
        if(arg0.getActionCommand().equals(TEST_COMMAND)){
            String ip = ipText.getText().trim();
            if(!Utility.checkIp(ip)){
                ipText.requestFocusInWindow();
                ipText.selectAll();
                JOptionPane.showMessageDialog(this,"Invalid Ip!!!");
                return;
            }
            String port = portText.getText().trim();
            if(port.equals("") ||  !Utility.isIntNumber(port)){
                portText.requestFocusInWindow();
                portText.selectAll();
                JOptionPane.showMessageDialog(this,"Invalid Port!!!");
                return;
            }
            String pass = rPassText.getText().trim();
            if(pass.equals("")){
                rPassText.requestFocusInWindow();
                rPassText.selectAll();
                JOptionPane.showMessageDialog(this,"Enter Rcon Password!!!");
                return;
            }
            RconBean rBean = RconBean.getBean();
            rBean.setIp(ip);
            rBean.setPassword(pass);
            rBean.setPort(Integer.parseInt(port));
            if(!Utility.testConnection()){
                rPassText.requestFocusInWindow();
                rPassText.selectAll();
                JOptionPane.showMessageDialog(this,"Invalid Rcon!!!");
                return;
            }else{
                JOptionPane.showMessageDialog(this,"Correct Rcon!!!");
                return;
            }
        }
        else if(arg0.getActionCommand().equals(CLEAR_COMMAND)){
            ipText.setText("");
            portText.setText("");
            rPassText.setText("");
        }
    }
}

它显示为

它已经裁剪了一些数据,如何将其完整显示并使小程序也无法调整大小。我试过setSize(400, 400);但这并没有帮助内部面积保持不变而外部边界增加


这是布局的另一种变体。使用@Andrew的tag-in-source方法,很容易从命令行进行测试:

$ /usr/bin/appletviewer HomeApplet.java
// <applet code='HomeApplet' width='400' height='200'></applet>
import java.awt.BorderLayout;
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.JTabbedPane;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;

public class HomeApplet extends JApplet {

    @Override
    public void init() {
        try {
            SwingUtilities.invokeAndWait(new Runnable() {

                @Override
                public void run() {
                    createGUI();
                }
            });
        } catch (Exception e) {
            e.printStackTrace(System.err);
        }
    }

    private void createGUI() {
        JTabbedPane tabbedPane = new JTabbedPane();
        tabbedPane.addTab("Rcon1", new RconSection());
        tabbedPane.addTab("Rcon2", new RconSection());
        this.add(tabbedPane);
    }

    private static class RconSection extends JPanel implements ActionListener {

        private static final String TEST_COMMAND = "test";
        private static final String CLEAR_COMMAND = "clear";
        private JTextField ipText = new JTextField();
        private JTextField portText = new JTextField();
        private JTextField rPassText = new JTextField();

        public RconSection() {
            super(new BorderLayout());
            JLabel ip = new JLabel("IP");
            JLabel port = new JLabel("Port");
            JLabel rPass = new JLabel("Rcon Password");
            JButton testButton = new JButton("Test");
            testButton.setActionCommand(TEST_COMMAND);
            testButton.addActionListener(this);
            JButton clearButton = new JButton("Clear");
            clearButton.setActionCommand(CLEAR_COMMAND);
            clearButton.addActionListener(this);
            JPanel panel = new JPanel(new GridLayout(3, 2));
            panel.add(ip);
            panel.add(ipText);
            panel.add(port);
            panel.add(portText);
            panel.add(rPass);
            panel.add(rPassText);
            JPanel buttons = new JPanel(); // default FlowLayout
            buttons.add(testButton);
            buttons.add(clearButton);
            add(panel, BorderLayout.NORTH);
            add(buttons, BorderLayout.SOUTH);
        }

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

小程序未显示完整 的相关文章

随机推荐

  • 构建无服务层的企业应用

    有很多教程教我们直接使用数据库来使用一些 ORM 但在现实生活中 我不记得有一个直接使用数据库而不是服务的大项目 所以这些教程的数量对我来说似乎很奇怪 直接连接的应用程序在数据库和应用程序之间的数据传输速度方面具有真正的优势 并且它们没有由
  • 多生产者多消费者多线程Java

    我正在尝试生产者 消费者问题的多个生产者 多个消费者用例 我使用 BlockingQueue 在多个生产者 消费者之间共享公共队列 下面是我的代码 Producer import java util concurrent BlockingQ
  • 构建GCC:bootstrap有哪些优点和缺点?

    我了解引导编译器构建的作用 但我不了解普通用户的优点和缺点 我认为对于 GCC 维护者来说是有价值的 配置GCC时 有两个选项 enable bootstrap and disable bootstrap 据我了解 对于普通编译器构建 en
  • SQL删除性能

    delete from a A where a ID 132 A表包含大约5000条记录 A ID是A表的主键 但是删除需要很长时间 有时它也会超时 该表包含三个索引 并由三个外键引用 谁能解释一下为什么即使我们是基于主键删除 它仍然需要很
  • 如何将所有请求修改为单个文件而不导致无限循环

    如何将所有请求发送到 www myurl com ANYTHING 并将它们全部发送到 www myurl com index php 我发现我可以通过以下方式发送所有内容 RewriteRule index php R Permanent
  • 无法在 Firefox 3.6 中的表格上获取最小高度

    我有一个问题 最小高度不适用于我绝对定位的桌子 但是 我可以使用高度在 IE 6 中工作 据我所知 IE 6 将高度视为最小高度 关于我如何让它发挥作用的任何线索 table cellspacing 0 style width 100 mi
  • Wii MotionPlus 支持

    我正在开发一个与Wiimote http en wikipedia org wiki Wii Remote 到目前为止我一直在使用维尤斯图书馆 http www wiiuse net 效果很好 然而 wiiuse 不支持运动加 http e
  • 定义 TypeScript 回调类型

    我在 TypeScript 中有以下类 class CallbackTest public myCallback public doWork void doing some work this myCallback calling call
  • 对象化关系:一对多,我可以有效地做到这一点吗?

    我对 Objectify 还很陌生 我有一个简单的问题 做某事的最好方法 假设我有一个允许人们发送和接收的应用程序 消息 为简单起见 请考虑电子邮件 当我的应用程序加载时 我没有 想要加载来自每个联系人的每条消息 向给定用户发送消息 那将是
  • 跨安装的 ios 唯一标识符

    我们需要唯一地标识该设备 并且它在安装 重新安装 时必须相同 到目前为止 我们一直在使用存储在钥匙串中的标识符 因此它在安装过程中仍然存在 现在 在 10 3 beta 版中 卸载应用程序时 钥匙串会自动删除 参考 https forums
  • Eclipse Neon CDT 运行配置未设置环境变量

    我刚刚从 Eclipse Kepler 升级到 Neon 3 发现除非在调试器下运行 否则在运行配置中设置环境变量不起作用 截至 2017 年 2 月 6 日 这被确定为 Neon 3 中的回归问题 但我一直无法找到解决方案 有其他人看到这
  • 在绘图文本过滤器中正确转义文本

    根据文件 应该用斜杠转义 但当我逃脱时 未添加文本 有错误消息说Stray near 但这是什么意思以及我该如何解决它 命令和输出 usr bin ffmpeg y i home www 255871 mov af aresample as
  • 为什么 Guava 中不推荐使用 Files.deleteDirectoryContents() ?

    在 Guava 10 中 Google 已弃用文件 deleteDirectoryContents https google github io guava releases 10 0 api docs com google common
  • GADT 上的模式匹配失败

    我更多地使用 ReasonML 并发现了模式匹配type t从以下示例开始 无法处理该错误 错误 此模式与 t float 类型的值匹配 但需要一个与 t int 类型的值匹配的模式 float 类型与 int 类型不兼容 type t a
  • Pandas str 和 object 类型的区别

    Numpy 似乎区分了str and object类型 例如我可以这样做 gt gt gt import pandas as pd gt gt gt import numpy as np gt gt gt np dtype str dtyp
  • 从文件读取清单时出现异常。 Microsoft Word 插件 VSTO

    我正在尝试创建一个 Microsoft Word 插件 每次保存 Word 文档 自动保存或手动保存 时 该插件都会添加并提交到 git 存储库 当我从 Visual Studio 调试模式 中运行程序时 我已经能够获得我想要的功能 当我发
  • constexpr 函数在多个模块中共享

    当我使用 constexpr 函数时 我注意到一个奇怪的行为 我将代码简化为一个简化的示例 从两个不同的翻译单元 模块 A 和 B 调用两个函数 include
  • IllegalStateException: 当前不在 FragmentManager 中

    我知道这听起来像是重复的FragmentStatePagerAdapter IllegalStateException 当前不在 FragmentManager 中 https stackoverflow com questions 112
  • 在我的 Node 应用程序中使用 SSH 连接到 MongoDB

    我的数据库使用 DigitalOcean 我正在尝试在我的节点应用程序中连接到它 我发现了一个名为的 npmtunnel ssh但是我无法连接到它 我的代码如下 它说数据库连接成功 但是当我执行console log mongoose 它显
  • 小程序未显示完整

    我刚刚创建了一个小程序 public class HomeApplet extends JApplet private static final long serialVersionUID 7650916407386219367L Call