开发者

Wrap Extended Frame View in a Window

开发者 https://www.devze.com 2023-04-08 02:30 出处:网络
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..

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();
           开发者_如何学C         }
                    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);
                }
            }
        });
    }
.........


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号