Simpler GUI why doesnt it work


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 4 of 4

Thread: Simpler GUI why doesnt it work

Hybrid View

  1. #1
    Join Date
    Sep 2006
    Posts
    23

    Simpler GUI why doesnt it work

    Code:
    import javax.swing.*;
    import java.util.*;
    public class Clock 
    {
    	JFrame frame=new JFrame();
    	frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    	frame.setTitle("Clock");
    	frame.setSize(550,220);
    	JLabel display=new JLabel();
    	display.setFont(new Font(Font.BOLD,38));
    	frame.getContentPane().add(display);
    	int last=-1;
    	do
    	{
    		Date current=new Date();
    		int sec=current.getSeconds();
    		if(last!=sec)
    		{
    			display.setText(current.toString());
    			last=sec;
    		}
    	}while(true);
    }
    }
    Why does it not work

  2. #2
    Join Date
    Dec 2005
    Posts
    97
    should be something like this:

    Code:
    import javax.swing.*;
    import java.util.*;
    import java.awt.*;
    public class Clock extends JFrame
    {
    	public static void main(String[] args)
    	{	
    		JFrame frame=new JFrame();
    		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		frame.setTitle("Clock");
    		frame.setPreferredSize(new Dimension(300,300));
    		JLabel display=new JLabel();		
    		frame.getContentPane().add(display);
    		frame.pack();
    		frame.setVisible(true);
    		int last=-1;
    		do
    		{
    			Date current=new Date();
    			int sec=current.getSeconds();
    			if(last!=sec)
    			{
    				display.setText(current.toString());
    				last=sec;
    			}
    		}while(true);
    	}
    }

  3. #3
    Join Date
    Sep 2006
    Posts
    23
    what does extends JFrame do
    frame.pack(); this line too?

  4. #4
    Join Date
    Dec 2005
    Posts
    97
    whoops well, you dont need to extend JFrame, so you can delete that. and frame.pack()

    Causes this Window to be sized to fit the preferred size and layouts of its subcomponents. If the window and/or its owner are not yet displayable, both are made displayable before calculating the preferred size. The Window will be validated after the preferredSize is calculated.

Similar Threads

  1. Data Entry Work
    By Anjana Jonathan in forum Careers
    Replies: 5
    Last Post: 07-03-2006, 03:15 AM
  2. Gui builders... help starting
    By pedrotuga in forum Open Source
    Replies: 2
    Last Post: 07-26-2005, 07:28 AM
  3. Heh heh.... GUI it is then :P -nt-
    By kleric in forum Java
    Replies: 0
    Last Post: 10-17-2000, 10:32 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center