I am designing the graphics for a game i am programming, i wanted to know if there is an easy way of opening a frame when a JLabel is cliked?
Is there easy code for this?

Surround the string with <html></html> and break the lines with <br/> . just a little correction: use <br /> instead of just <br> ... this is recommended way of doing it (to not miss any closing tags)...
Implement MouseListener interface and use it mouseClicked method to handle the clicks on the JLabel. 
label.addMouseListener(new MouseAdapter()  
{  
    public void mouseClicked(MouseEvent e)  
    {  
       // you can open a new frame here as
       // i have assumed you have declared "frame" as instance variable
       frame = new JFrame("new frame");
       frame.setVisible(true);
    }  
}); 
create a label and add click event in it .
Something like this :
JLabel click=new JLabel("Click me");
 click.addMouseListener(new MouseAdapter() {
        public void mouseClicked(MouseEvent e) {
           JFrame jf=new JFrame("new one");
        jf.setBackground(Color.BLACK);
        jf.setSize(new Dimension(200,70));
        jf.setVisible(true);
        jf.setDefaultCloseOperation(EXIT_ON_CLOSE);
        }
    });
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With