Ask Experts Questions for FREE Help !
Ask
    BK MEN's Avatar
    BK MEN Posts: 1, Reputation: 1
    New Member
     
    #1

    Oct 11, 2015, 09:44 AM
    JComboBox problem with repaint() methos
    I am new to Java and I'm creating a clock with time zone. I have a little problem with JComboBox's repaint method. If I put repaint() in my code I can't see the JComboBox in the Applet window, and if I remove repaint() then it is visible. As you know it is very necessary to put repaint() in your code.
    Analyse my code and tell me...
    What am I doing wrong?


    ` package apps;


    import java.awt.*;


    import java.awt.event.*;


    import java.util.Calendar;


    import javax.swing.*;


    public class Alarm2 extends JFrame implements ItemListener,Runnable{


    private Graphics dbg;


    private Image dbImage;


    JComboBox c=new JComboBox();


    Thread t;


    int h,m,s;


    boolean alarm=false;


    String time="";






    TextField tf=new TextField("SEX:",10);


    Alarm2(){










    setTitle("BALVEER");


    setSize(250,250);


    setResizable(false);


    setLocationRelativeTo(null);


    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);


    c.addItem("MALE");


    c.addItem("FEMALE");


    setBackground(Color.GREEN);




    c.addItemListener(this);


    add(c);


    add(tf);


    setLayout(new FlowLayout(FlowLayout.RIGHT,10,195));


    setVisible(true);




    }
    public void aisha(){


    t=new Thread(this);


    t.start();






    }
    public void run(){


    try{


    while(true){


    Calendar cal=Calendar.getInstance();


    h=cal.get(Calendar.HOUR);


    m=cal.get(Calendar.MINUTE);




    s=cal.get(Calendar.SECOND);


    t.sleep(1000);


    time=" "+h+" : "+m+" : "+s;


    repaint();






    }






    }


    catch(Exception e){






    }
    }


    public void itemStateChanged(ItemEvent e){


    tf.setText("SEX: "+e.getItem());


    }






    public void paint(Graphics g){


    dbImage =createImage(getWidth(),getHeight());




    dbg=dbImage.getGraphics();


    draw(dbg);


    g.drawImage(dbImage,0,0,this);


    }


    public void draw(Graphics g){


    g.setColor(Color.red);


    g.drawString("TIME:"+time, 50, 100);






    }


    public static void main(String[] args) {


    Alarm2 java=new Alarm2();


    java.aisha();


    }
    }`

Check out some similar questions!

Jcombobox in jtable [ 0 Answers ]

I am setting a JComboBox in a JTable. The first item in the JComboBox is the JComboBox string object: javax.swing.JComboBox If I click on the JComboBox in the table column, it opens up with the items I have added. TableColumn col = Table.getColumnModel().getColumn(1);...

How to repaint a chipped concrete shower floor? [ 2 Answers ]

I have a concrete shower floor where the existing paint is chipped. I would like to repaint it. What is the best way to do this?

Repaint aluminum deck fenscing [ 8 Answers ]

I have extensive aluminum deck fencing around my decks and stairways. A few days ago I had them cleaned by power washing and a lot of the paint was washed off. What kind of paint should I use to repaint the aluminum? Thank you.

Need to repaint Fender Squire jagmaster [ 3 Answers ]

Hi, My son has an electrict guitar that he wants to refinish/repaint and I was wondering if anyone has done this before and could point us in the right direction. Is it too difficult for just anyone to do? Thanks :)

How to clean old paint and repaint shower walls and floor [ 1 Answers ]

How do I clean old paint that is peeling off the walls and floor of painted cement block shower? What products should be used to repaint?


View more questions Search
 

Question Tools Search this Question
Search this Question:

Advanced Search

Add your answer here.