Action Listener in main class
play.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Game g= new Game();
add(g);
}
});
Constructor of Game class
Game(){
Container c=this.getContentPane();
c.setVisible(true);
this.setVisible(true);
add(new g());
addMouseListener(new ml());
this.setBounds(100,100,200,300);
this.setTitle("LEVEL 1:");
for(int loop=0;loop<=10;loop++){
ballfall();
}
ScoreScreen sc= new ScoreScreen();
sc.setmethod(String.valueOf(sum));
}
I am making a game in which the there is homescreen where user clicks playbutton and another screen appears where the main game is.The problem is when I click play button a blank black screen appears and nothing happens. But when I create Game oibject in main method , it works fine but it doesn't work when its object is created in Action Listener. I've even added the object g in add().