小编kno*_*erg的帖子

为什么我的JFrame内容无法正确显示?

为了减少代码,我正在取出与问题无关的代码,例如addActionListener();等.

我的主要课程是 public class TF2_Account_Chief

我有我的主要Jframe f;内容:

private static JFrame f = new JFrame("TF2 Account C.H.I.E.F.");
private JLabel runnableTogetherLabel = new JLabel("How many idlers would you like to run at a time?");
private static JTextField runnableTogetherInput = new JTextField();
private JButton runButton = new JButton("Run!");
private JButton stopButton = new JButton("Stop!");
private JButton resetButton = new JButton("Reset!");
private JButton exitButton = new JButton("Exit!");
Run Code Online (Sandbox Code Playgroud)

我设置了所有内容的属性:

    public void launchFrame() {
        f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        f.pack();
        f.setVisible(true);
        f.add(runnableTogetherInput);
        f.add(runnableTogetherLabel);
        f.add(runButton);
        f.add(stopButton);
        f.add(resetButton); …
Run Code Online (Sandbox Code Playgroud)

java swing jframe

3
推荐指数
1
解决办法
1381
查看次数

如何在主类中扩展JFrame和JPanel?

所以我希望我的主类扩展JFrame和JPanel.我该怎么做?

例如:

public class mainClass extends JFrame {
//code here
}
Run Code Online (Sandbox Code Playgroud)

我如何为同一个类扩展JPanel?

提前致谢!

java swing extends jpanel jframe

2
推荐指数
1
解决办法
6521
查看次数

为什么我的NumberFormatException没有被我的try-catch捕获?

所以我想catch (NumberFormatException ex)在我的代码中:

private void Processes() throws IOException, InterruptedException {
    // New Thread "processesThread" will start here.
    final Object mon = threadBlock;
    Thread processesThread = new Thread(new Runnable() {
        @Override
        public void run() {
            synchronized (mon) {
                try {
                    try {
                        try {
                            Runtime rt = Runtime.getRuntime();
                            // "runnableTogether" will be the number that the user inputs in the GUI.
                            switch (runnableTogether) {
                                case 4:
                                processes.add(rt.exec("C:/Windows/System32/SoundRecorder.exe"));
                                case 3:
                                processes.add(rt.exec("C:/Windows/System32/taskmgr.exe"));
                                case 2:
                                processes.add(rt.exec("C:/Windows/System32/notepad.exe"));
                                case 1:
                                processes.add(rt.exec("C:/Windows/System32/calc.exe"));
                                Thread.sleep(5000);
                                destroyProcesses(processes);
                                break; …
Run Code Online (Sandbox Code Playgroud)

java swing exception-handling try-catch numberformatexception

0
推荐指数
1
解决办法
1108
查看次数