[英]Java swing gui program with keylisteners that does not work in linux
[英]TaskManager for linux - Does Java Swing work on Linux?
我将开发Linux的任务管理器,并处于初始阶段。 首先,我在Windows平台的Java Eclipse中实现了它,它运行得很好。 它在Linux平台上不起作用。 我使用了Java / Swing的组合。
Windows中的“tasklist.exe”工作正常。 linux中的“ps-aux”不起作用。
码:
package test.t100.t001;
import java.awt.*;
import java.awt.event.KeyEvent;
import java.io.BufferedReader;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintStream;
import javax.swing.*;
public class TabbedPaneDemo extends JPanel {
private static final long serialVersionUID = 1L;
Integer i;
JTextArea output = new JTextArea();
public static void main(String args[])
{
SwingUtilities.invokeLater(new Runnable() {
public void run()
{
JFrame frame = new JFrame("TabbedPaneDemo");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add(new TabbedPaneDemo(), BorderLayout.CENTER);
frame.pack();
frame.setVisible(true);
}
});
}
private String getDetails() throws IOException {
//fn();
String line;
String result = "";
PrintStream p;
Process p1 = Runtime.getRuntime().exec("tasklist.exe");
// read from a process
BufferedReader input = new BufferedReader(
new InputStreamReader(p1.getInputStream()));
while ((line = input.readLine()) != null)
{
//System.out.println(line);
output.append(line + "\n");
result += line+"\n";
//p.println (line);
//textarea.setVisible(true);
}
//msgBox(result);
//p.close();
input.close();
return result;
}
public TabbedPaneDemo() {
super(new GridLayout(1, 1));
JTabbedPane tabbedPane = new JTabbedPane();
ImageIcon icon = createImageIcon("images");
JComponent panel1 = makeTextPanel("tasklist");
tabbedPane.addTab("tasks", icon, panel1,
"ta");
// add it to something!
panel1.add(new JScrollPane(output));
tabbedPane.setMnemonicAt(0, KeyEvent.VK_1);
JComponent panel2 = makeTextPanel("windows");
tabbedPane.addTab("wins", icon, panel2,
"wi");
tabbedPane.setMnemonicAt(1, KeyEvent.VK_2);
add(tabbedPane);//`enter code here`
tabbedPane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
try {
String s = getDetails();
output.setText(s);
} catch(IOException e) {
e.printStackTrace();
}
}
public static void msgBox(String msg) {
javax.swing.JOptionPane.showConfirmDialog((java.awt.Component)
null, msg, "WindowsUtils",
javax.swing.JOptionPane.DEFAULT_OPTION);
}
protected JComponent makeTextPanel(String text)
{
JPanel panel = new JPanel(false);
JLabel filler = new JLabel(text);
filler.setHorizontalAlignment(JLabel.CENTER);
panel.setLayout(new GridLayout(1, 1));
panel.add(filler);
return panel;
}
protected static ImageIcon createImageIcon(String path) {
java.net.URL imgURL = TabbedPaneDemo.class.getResource(path);
if (imgURL != null) {
return new ImageIcon(imgURL);
} else {
System.err.println("Couldn't find file: " + path);
return null;
}
}
}
我假设Java Swings
你的意思是Java Swing
。 Java是跨平台的,因此除非您使用一些外部库(具有特定于平台的调用),否则您应该能够在任何平台上编译和运行。
话虽这么说,按照这个以前SO后, ps -ef
将让你所有运行的任务,这样看来,你可以使用了错误的选择。
我假设您尝试执行此代码的Linux平台具有某种GUI,而不是那些基于控制台的发行版之一。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.