English 中文(简体)
创造数个独立的图形用户界面的最佳方法是什么?
原标题:Java: What s the best way to generate several independent GUIs?

我需要显示多个图像, 以便用户可以比较它们, 我不知道使用什么方法 。 我有一个程序允许用户选择图像文件, 所以我有一个文件对象 。 我曾尝试用“ 新” 生成新的图形界面, 但效果不好 。

Should I code a standalone app (with a main) and use a system call to start them with a new JVM? I m new at Java and have just touched the surface of AWT and SWING.

此类的名称是任意的独有字符串 :

ImageWindowStub iw = new ImageWindowStub(name);

这是简单的代码,可以证明问题,如果连续被调用的话。

package fireScience.airborne.image;

import java.awt.Dimension;

import javax.swing.BoxLayout;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingConstants;
import javax.swing.SwingUtilities;
import javax.swing.border.BevelBorder;

public class ImageWindowStub {


private static JFrame frame;
private static JPanel statusPanel;
private static JLabel statPixInfoLbl;

private static String theString;

public ImageWindowStub(String theString) {
    this.theString = theString;
    statusPanel = new JPanel();
    createAndShowGui();

}

private static void createAndShowGui() {
    SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
            frame = new JFrame(theString);
            JFrame.setDefaultLookAndFeelDecorated(true);
            frame.setResizable(true);
            frame.setSize(300, 200);
            frame.setLocation(50, 50);
            statusPanel = new JPanel();
            statusPanel.setBorder(new BevelBorder(BevelBorder.LOWERED));
            statusPanel.setPreferredSize(new Dimension(frame.getWidth(), 24));
            statusPanel.setLayout(new BoxLayout(statusPanel,
                    BoxLayout.X_AXIS));
            statPixInfoLbl = new JLabel("Status Bar");
            statPixInfoLbl.setHorizontalAlignment(SwingConstants.LEFT);
            statusPanel.add(statPixInfoLbl);
            frame.add(statusPanel);
            frame.pack();
            frame.setVisible(true);
        }

    });
}

}

我的核心问题是“什么是产生多重独立图形用户界面类的最佳方式?”

问题回答

我猜你想要的是"http://docs.oracle.com/javase/tuative/uiswing/parties/ interframe.html" rel=“nofollow” > 内部框架 。每个内部框架将有一个主的JPanel ,包含一个 JLabel ,持有一个 ImagiIcon

您可以根据您要显示的内容, 将内部框打瓷砖或覆盖。

I think I have found an answer, not quite what I wanted, but it appears to work. I added a main which takes a string argument:

public static void main(String[] args) {
    if (args.length > 0) {
        ImageWindowStub iws = new ImageWindowStub(args[0]);
    } else {
        ImageWindowStub iws = new ImageWindowStub("Testing: No arg passed");
    }
}

然后导出一个可执行的罐子文件, 并由此创建实例 :

            Process p;
            try {
                p = Runtime.getRuntime().exec(command);
            } catch (IOException e1) {
                // TODO Auto-generated catch block
                e1.printStackTrace();
            }

此处的“ 命令” 是带有完全合格的路径名称的字符串, 与可执行文件罐加上参数 。

到目前为止,我似乎可以创造多个放弃 p. 先前的值的例子。 显示的框不会在调用程序退出时退出, 但似乎可以实施此行为 。





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签