Dla większej przejrzystości usunąłem wszystko to co niepotrzebne i zostawiłem wyłącznie komponenty, które powinny być i JButton, o który się rozchodzi.
Kod: Zaznacz cały
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package puzzle;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
/**
*
* @author rafalstwa
*/
public class Main implements MouseListener{
JButton next;
JFrame mainframe;
public void Poczatek() {
JFrame mainframe = new JFrame("Gierka1");
mainframe.setLayout(null);
mainframe.setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE);
int wmainframe = 720;
int hmainframe = 480;
mainframe.setSize(wmainframe, hmainframe);
Toolkit tool = Toolkit.getDefaultToolkit();
Dimension sizeScreen = tool.getScreenSize();
int wScreen = sizeScreen.width;
int hScreen = sizeScreen.height;
mainframe.setLocation((wScreen/2-wmainframe/2), (hScreen/2-hmainframe/2));
Font Serifduza = new Font("Serif", Font.BOLD, 20) ;
Font Serifmala = new Font("Serif", Font.BOLD, 15) ;
JLabel tekst1 = new JLabel("Puzzle");
tekst1.setBounds(wmainframe/2-50, 100,100, 30);
tekst1.setFont(Serifduza);
JButton next = new JButton("Przejdz dalej");
next.setBounds(wmainframe-200, 400, 170, 40);
next.setFont(Serifmala);
next.addMouseListener(this);
mainframe.getContentPane().setBackground(Color.WHITE);
mainframe.getContentPane().add(tekst1);
mainframe.getContentPane().add(next);
mainframe.setVisible(true);
}
public void mouseEntered(MouseEvent e) {if (e.getSource() == next){mainframe.getContentPane().removeAll();}}
public void mouseExited(MouseEvent e) {}
public void mousePressed(MouseEvent e) {if (e.getSource() == next) {mainframe.getContentPane().removeAll();}}
public void mouseReleased(MouseEvent e){}
public void mouseClicked(MouseEvent e) {if (e.getSource() == next) {mainframe.getContentPane().removeAll();}}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
Main nowa = new Main();
nowa.Poczatek();
}
}