将扩展框架视图包裹在窗口中

发布于 2024-12-06 19:31:39 字数 5189 浏览 1 评论 0原文

我的大学给我布置了一个作业,要继续上学期学生的 JAVA 卡项目,但结果很糟糕。因为我们必须继续别人的工作而不是我们的工作。

所以我的第一步是为应用程序的窗口制作一个窗口图像图标和托盘图标。 问题是,下面的代码基于扩展的 FrameView 而不是 JWindow。

我的想法是将扩展的 FrameView 包装到一个窗口中。

有人可以帮助我吗?

非常感谢,我将不胜感激。

代码:

public class DesktopApplication1View extends FrameView implements IProgressDialogObserver
{
    //============================================================
    // Fields
    // ===========================================================

    private Connection connection = new Connection();
    private ProgressDialogUpdater pbu = ProgressDialogUpdater.getInstance();
    private Vector<CourseFromCard> courseListFromCard = new Vector<CourseFromCard>();
    private Vector<School> schoolList = new Vector<School>();
    private Vector<CourseFromFile> courseList = new Vector<CourseFromFile>();
    private int cardReaderRefreshHelper = 0;
    private Student student = null;

    JLabel jLabelBilkaImage = null;

    final String ICON = new File("").getAbsolutePath() + System.getProperty("file.separator") + "src" + System.getProperty("file.separator") + "resources" + System.getProperty("file.separator") + "image" + System.getProperty("file.separator") + "BilKa_Icon_32.png";

    final String PIC = new File("").getAbsolutePath() + System.getProperty("file.separator") + "src" + System.getProperty("file.separator") + "resources" + System.getProperty("file.separator") + "image" + System.getProperty("file.separator") + "BilKa_Icon_128.png";

    private JLabel getJLabelBilkaImage() {
        if (jLabelBilkaImage == null) {
            Icon image = new ImageIcon(PIC);
            jLabelBilkaImage = new JLabel(image);
            jLabelBilkaImage.setName("jLabelBilkaImage");
        }
        return jLabelBilkaImage;
    }

    //============================================================
    // Constructors
    // ===========================================================

    public DesktopApplication1View(SingleFrameApplication app)
    {
        super(app);
        pbu.registriere(this);


        app.getMainFrame().setIconImage(Toolkit.getDefaultToolkit().getImage("icon.png"));

        initComponents();
        refreshConnectionState();
        readFilesFromLocalHDD();
        ResourceMap resourceMap = getResourceMap();
        int messageTimeout = resourceMap.getInteger("StatusBar.messageTimeout");
        messageTimer = new Timer(messageTimeout, new ActionListener()
        {
          public void actionPerformed(ActionEvent e)
            {
                statusMessageLabel.setText("");
            }
        });
        messageTimer.setRepeats(false);
        int busyAnimationRate = resourceMap.getInteger("StatusBar.busyAnimationRate");
        for (int i = 0; i < busyIcons.length; i++)
        {
            busyIcons[i] = resourceMap.getIcon("StatusBar.busyIcons[" + i + "]");
        }
        busyIconTimer = new Timer(busyAnimationRate, new ActionListener()
        {

            public void actionPerformed(ActionEvent e)
            {
                busyIconIndex = (busyIconIndex + 1) % busyIcons.length;
                statusAnimationLabel.setIcon(busyIcons[busyIconIndex]);
            }
        });
        idleIcon = resourceMap.getIcon("StatusBar.idleIcon");
        statusAnimationLabel.setIcon(idleIcon);
        progressBar.setVisible(false);

        // connecting action tasks to status bar via TaskMonitor
        TaskMonitor taskMonitor = new TaskMonitor(getApplication().getContext());
        taskMonitor.addPropertyChangeListener(new java.beans.PropertyChangeListener()
        {

            public void propertyChange(java.beans.PropertyChangeEvent evt)
            {
                String propertyName = evt.getPropertyName();
                if ("started".equals(propertyName))
                {
                    if (!busyIconTimer.isRunning())
                    {
                        statusAnimationLabel.setIcon(busyIcons[0]);
                        busyIconIndex = 0;
                        busyIconTimer.start();
                    }
                    progressBar.setVisible(true);
                    progressBar.setIndeterminate(true);
                }
                else if ("done".equals(propertyName))
                {
                    busyIconTimer.stop();
                    statusAnimationLabel.setIcon(idleIcon);
                    progressBar.setVisible(false);
                    progressBar.setValue(0);
                }
                else if ("message".equals(propertyName))
                {
                    String text = (String) (evt.getNewValue());
                    statusMessageLabel.setText((text == null) ? "" : text);
                    messageTimer.restart();
                }
                else if ("progress".equals(propertyName))
                {
                    int value = (Integer) (evt.getNewValue());
                    progressBar.setVisible(true);
                    progressBar.setIndeterminate(false);
                    progressBar.setValue(value);
                }
            }
        });
    }
.........

I have an assignment from my university to continue a JAVA card project from the students from last semester, which happens to be sucked. Because we have to carry on with someones work instead ours..

So my first step is to make an window image icon and tray icon for the application`s window.
The thing is, this code below is based on extended FrameView instead of JWindow.

My idea is to wrap the extended FrameView up into a Window.

Can someone help me with that?

Thanks much I would appreciate that.

CODE:

public class DesktopApplication1View extends FrameView implements IProgressDialogObserver
{
    //============================================================
    // Fields
    // ===========================================================

    private Connection connection = new Connection();
    private ProgressDialogUpdater pbu = ProgressDialogUpdater.getInstance();
    private Vector<CourseFromCard> courseListFromCard = new Vector<CourseFromCard>();
    private Vector<School> schoolList = new Vector<School>();
    private Vector<CourseFromFile> courseList = new Vector<CourseFromFile>();
    private int cardReaderRefreshHelper = 0;
    private Student student = null;

    JLabel jLabelBilkaImage = null;

    final String ICON = new File("").getAbsolutePath() + System.getProperty("file.separator") + "src" + System.getProperty("file.separator") + "resources" + System.getProperty("file.separator") + "image" + System.getProperty("file.separator") + "BilKa_Icon_32.png";

    final String PIC = new File("").getAbsolutePath() + System.getProperty("file.separator") + "src" + System.getProperty("file.separator") + "resources" + System.getProperty("file.separator") + "image" + System.getProperty("file.separator") + "BilKa_Icon_128.png";

    private JLabel getJLabelBilkaImage() {
        if (jLabelBilkaImage == null) {
            Icon image = new ImageIcon(PIC);
            jLabelBilkaImage = new JLabel(image);
            jLabelBilkaImage.setName("jLabelBilkaImage");
        }
        return jLabelBilkaImage;
    }

    //============================================================
    // Constructors
    // ===========================================================

    public DesktopApplication1View(SingleFrameApplication app)
    {
        super(app);
        pbu.registriere(this);


        app.getMainFrame().setIconImage(Toolkit.getDefaultToolkit().getImage("icon.png"));

        initComponents();
        refreshConnectionState();
        readFilesFromLocalHDD();
        ResourceMap resourceMap = getResourceMap();
        int messageTimeout = resourceMap.getInteger("StatusBar.messageTimeout");
        messageTimer = new Timer(messageTimeout, new ActionListener()
        {
          public void actionPerformed(ActionEvent e)
            {
                statusMessageLabel.setText("");
            }
        });
        messageTimer.setRepeats(false);
        int busyAnimationRate = resourceMap.getInteger("StatusBar.busyAnimationRate");
        for (int i = 0; i < busyIcons.length; i++)
        {
            busyIcons[i] = resourceMap.getIcon("StatusBar.busyIcons[" + i + "]");
        }
        busyIconTimer = new Timer(busyAnimationRate, new ActionListener()
        {

            public void actionPerformed(ActionEvent e)
            {
                busyIconIndex = (busyIconIndex + 1) % busyIcons.length;
                statusAnimationLabel.setIcon(busyIcons[busyIconIndex]);
            }
        });
        idleIcon = resourceMap.getIcon("StatusBar.idleIcon");
        statusAnimationLabel.setIcon(idleIcon);
        progressBar.setVisible(false);

        // connecting action tasks to status bar via TaskMonitor
        TaskMonitor taskMonitor = new TaskMonitor(getApplication().getContext());
        taskMonitor.addPropertyChangeListener(new java.beans.PropertyChangeListener()
        {

            public void propertyChange(java.beans.PropertyChangeEvent evt)
            {
                String propertyName = evt.getPropertyName();
                if ("started".equals(propertyName))
                {
                    if (!busyIconTimer.isRunning())
                    {
                        statusAnimationLabel.setIcon(busyIcons[0]);
                        busyIconIndex = 0;
                        busyIconTimer.start();
                    }
                    progressBar.setVisible(true);
                    progressBar.setIndeterminate(true);
                }
                else if ("done".equals(propertyName))
                {
                    busyIconTimer.stop();
                    statusAnimationLabel.setIcon(idleIcon);
                    progressBar.setVisible(false);
                    progressBar.setValue(0);
                }
                else if ("message".equals(propertyName))
                {
                    String text = (String) (evt.getNewValue());
                    statusMessageLabel.setText((text == null) ? "" : text);
                    messageTimer.restart();
                }
                else if ("progress".equals(propertyName))
                {
                    int value = (Integer) (evt.getNewValue());
                    progressBar.setVisible(true);
                    progressBar.setIndeterminate(false);
                    progressBar.setValue(value);
                }
            }
        });
    }
.........

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

故事未完 2024-12-13 19:31:39

SingleFrameApplication 提供了 getMainFrame() 方法,该方法返回用于显示特定视图的 JFrame。您在问题中列出的代码就是这样一种视图。如果您需要对框架进行操作,那么在子类化 SingleFrameApplication 的代码中可能比您发布的代码更好。

有一个关于使用 Swing 应用程序框架的教程,它可能会提供更多帮助。

SingleFrameApplication provides the method getMainFrame(), which returns the JFrame used to display a particular view. The code you listed in your question is one such view. If you need to operate on the frame, it's probably better to do it in code subclassing SingleFrameApplication than the code you posted.

There's a tutorial on using the Swing Application Framework, which might provide more help.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文