Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

help me with swing

  Asked By: Phil    Date: May 20    Category: Java    Views: 738
  

my frame shows nothing unless it is resized

//xMac

package MyProg;
import java.util.*;
import javax.swing.*;
import java.awt.*;

public class MyClock extends JFrame
{
protected MyJPanel jp;
protected JLabel a1;
protected JLabel a2;

public MyClock()
{
super("xMac");
// getting the Time
Calendar now= Calendar.getInstance();
int hour1=now.get(Calendar.HOUR_OF_DAY);
int min=now.get(Calendar.MINUTE);
int sec=now.get(Calendar.SECOND);

//initialize the compo.
a1=new JLabel("Time is:");
a2=new JLabel("");
jp= new MyJPanel();

//setting the frame up
setContentPane(jp);
setVisible(true);
setSize(150,60);

jp.add(a1);
jp.add(a2);



for(int h=hour1;;h++)
{
for(int m=min;m<=59;m++)
{
for(int s=sec;s<=59;s++)
{
try
{
Thread.sleep(1000);
a2.setText(h+":"+m+":"+s);
}
catch(Exception e)
{
}
if(s==59)
sec=0;
}
if(m==59)
min=0;
}
if(h==23)
hour1=0;
}


}

public static void main(String []xMac)
{
MyClock mc=new MyClock();
}

}

class MyJPanel extends JPanel
{
public void paintComponent(Graphics g )
{
super.paintComponent(g );
}
}



Share: 

 

1 Answer Found

 
Answer #1    Answered By: Dylan Evans     Answered On: May 20

try this ...

public static  void main(String []xMac)
{
MyClock mc=new MyClock();
mc.pack();
mc.show();
}

 
Didn't find what you were looking for? Find more on help me with swing Or get search suggestion and latest updates.




Tagged: