2011-09-25 63 views
1

我有一份来自我的大学的作业,继续从上学期的学生处继续进行JAVA卡片项目,该项目恰好被吸引。因为我们必须继续与某人工作,而不是我们的..在窗口中包装扩展框架视图

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

我的想法是将扩展的FrameView放到窗口中。

有人可以帮我吗?

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

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); 
       } 
      } 
     }); 
    } 
......... 
+1

为什么? Appframework有助于组织应用程序,学习如何充分利用它并获得快乐:-) – kleopatra

回答

1

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

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