1

特定の関数を呼び出して詳細を印刷する方法がわからないという小さな問題があります。PCの合計物理メモリをチェックするラジオボタンを作成しました。GPU用のラジオボタンもあり、どちらも正常に機能します。

同じ関数を呼び出す方法がわからなくなったため、特定のシステムプロパティのシステムスキャンを実行すると、より大きなウィンドウに出力されます。

if (isWindows()) {

        jTextArea1.setText(header + "User Name : " + name
                + "\nOperating System :" + jComboBox1.getSelectedItem()
                + "\nSelected Gamer Ability : " + this.jComboBox4.getSelectedItem()
                + "\nSelected Age Group :" + this.jComboBox5.getSelectedItem()
                + "\nSystem Version : " + System.getProperty("os.version")
                + "\nSystem Architecture : " + System.getProperty("os.arch")
  PROBLEM PART  + "\nSystem Total Ram : " + this.jRadioButton2......
                + "\nScan ID : " + n + "\n \n")

 }



private void jRadioButton1ActionPerformed(java.awt.event.ActionEvent evt)       {                                              
    String filepath = "..\\Checker\\src\\batchchecker\\memory.bat";
    try 
    {
        Process p = Runtime.getRuntime().exec(filepath); // filepath
        p.waitFor();
        InputStream in = p.getInputStream();
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        int c = -1;
        while ((c = in.read()) != -1) 
        {
            baos.write(c);
        }
        String response = new String(baos.toByteArray());
        jRadioButton2.setText(evt.getActionCommand());
        JOptionPane.showMessageDialog(null, "" + evt.getActionCommand()
            + response);

        }
        catch (Exception e) 
        {
            e.printStackTrace(System.err);
        }
    }
}

上記のコードからわかるように、私のラジオは必要なことを実行してテストしました。同じ結果をより大きな画像に呼び出して、実際にすべての詳細を残りの部分と一緒に印刷する方法がわかりません。コードの行は+ "\nSystem Total Ram : " + this.jRadioButton2......

4

1 に答える 1

0

actionPerformed()メソッドと他の呼び出しの両方から呼び出すことができる別のメソッドに実装を移動する必要があるようです。例えば:

public String findMemoryDetails() {
    // ... put code here
}

次に、ここでそれを呼び出します:

private void jRadioButton1ActionPerformed(java.awt.event.ActionEvent evt) {
    String memDetails = findMemoryDetails();
    JOptionPane.showMessageDialog(null, "" + evt.getActionCommand() + memDetails);
}

そしてここ:

+ "\nSystem Total Ram : " + findMemoryDetails()
于 2012-12-05T17:43:05.250 に答える