Почему при запуске в Linux не отображается ни один кадр?

1

У меня есть следующий код. Когда я запускаю его в Windows, появляется фрейм. Но когда я запускаю Linux, ничего не появляется. Я попытался разместить show() ниже строки contentPane.setLayout(null); внутри конструктора. Это показало форму. Но никаких ярлыков или кнопок не было внутри. Пожалуйста, помогите:

    public class MainFrame extends JFrame {

    private JPanel contentPane;
    Process p;
    String s;

    /**
     * Launch the application.
     */
    public static void main(String[] args) {
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                try {
                    MainFrame frame = new MainFrame();
                    frame.setVisible(true);
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        });
    }

    /**
     * Create the frame.
     */
    public MainFrame() {
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setBounds(100, 100, 549, 426);
        contentPane = new JPanel();
        contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
        setContentPane(contentPane);
        contentPane.setLayout(null);

        JLabel lblRam = new JLabel("RAM");
        lblRam.setFont(new Font("Tahoma", Font.PLAIN, 48));
        lblRam.setBounds(212, 0, 140, 77);
        contentPane.add(lblRam);

        final JTextArea textArea = new JTextArea();
        textArea.setBounds(10, 88, 384, 215);
        contentPane.add(textArea);

        JButton btnRamInfo = new JButton("System Memory");
        btnRamInfo.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                textArea.setText("");
                repaint();

                 try{
                     p = Runtime.getRuntime().exec("cat /proc/meminfo");
                     BufferedReader br = new BufferedReader(
                         new InputStreamReader(p.getInputStream()));
                     while ((s = br.readLine()) != null)
                         textArea.setText(s);
                     p.waitFor();
                     p.destroy();

                     }
                 catch(Exception e)
                 {

                 }
            }
        });
        btnRamInfo.setBounds(404, 139, 119, 34);
        contentPane.add(btnRamInfo);

         try{
             p = Runtime.getRuntime().exec("free -ms 5");
             BufferedReader br = new BufferedReader(
                 new InputStreamReader(p.getInputStream()));
             while ((s = br.readLine()) != null)
                 textArea.setText(s);
             p.waitFor();
             System.out.println ("exit: " + p.exitValue());
             p.destroy();
             }
         catch(Exception e)
         {

         }


         JButton btnNewButton = new JButton("Advanced");
         btnNewButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent arg0) {
                textArea.setText("");
                repaint();
                 try{
                     p = Runtime.getRuntime().exec("dmidecode –type memory");
                     BufferedReader br = new BufferedReader(
                         new InputStreamReader(p.getInputStream()));
                     while ((s = br.readLine()) != null)
                         textArea.setText(s);
                     p.waitFor();
                     p.destroy();
                     }
                 catch(Exception e)
                 {

                 }
            }
         });
         btnNewButton.setBounds(404, 89, 119, 34);
         contentPane.add(btnNewButton);


    }
   }
  • 0
    Вы пытались удалить части кода по одной? Похоже, вы могли бы сделать это довольно легко с помощью этого кода.
  • 0
    null расположение - первое предупреждение, setBounds кадра - второе. Попробуйте вместо этого использовать setLocationRelativeTo(null)
Показать ещё 2 комментария
Теги:
user-interface
swing
jframe

1 ответ

2
Лучший ответ

Может быть из-за этой части кода, который находится между двумя кнопками. Попробуйте удалить его и увидеть:

  try{
     p = Runtime.getRuntime().exec("free -ms 5");
     BufferedReader br = new BufferedReader(
         new InputStreamReader(p.getInputStream()));
     while ((s = br.readLine()) != null)
         textArea.setText(s);
     p.waitFor();
     System.out.println ("exit: " + p.exitValue());
     p.destroy();
     }
 catch(Exception e)
 {

 }
  • 0
    Спасибо, это работает!! но почему???

Ещё вопросы

Сообщество Overcoder
Наверх
Меню