package game;
import java.applet.Applet;
import java.net.URL;
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.event.*;
import java.io.*;
public class Menu extends JFrame
{
ClassLoader cl = this.getClass().getClassLoader();
//panel z tlem:
JBackgroundPanel tlo = new JBackgroundPanel("img\\bg3.gif");
//JBackgroundPanel tlo = new JBackgroundPanel("img\\bg3.gif");
//przyciski:
ImageIcon graj = new ImageIcon(cl.getResource( "img\\graj.gif"));
ImageIcon jakgrac = new ImageIcon(cl.getResource( "img\\jakgrac.gif"));
//ImageIcon wyniki = new ImageIcon(cl.getResource( "img\\wyniki.gif"));
ImageIcon opcje = new ImageIcon(cl.getResource( "img\\opcje.gif"));
ImageIcon koniec = new ImageIcon(cl.getResource( "img\\koniec.gif"));
JButton b1 = new JButton(graj);
JButton b2 = new JButton(jakgrac);
//JButton b3 = new JButton(wyniki);
JButton b4 = new JButton(opcje);
JButton b5 = new JButton(koniec);
public Menu()
{
super("Menu Gry");
Container cp = getContentPane();
cp.setLayout(new BorderLayout()); //FlowLayout, GridLayout(3,2)
tlo.setLayout(new BoxLayout(tlo, BoxLayout.Y_AXIS)); //BoxLayout(tlo, BoxLayout.Y_AXIS)
cp.add(tlo, "Center");
//dodanie i pozycjonowanie przyciskow:
tlo.add(Box.createRigidArea(new Dimension(250, 0)));
tlo.add(Box.createRigidArea(new Dimension(0, 75)));
tlo.add(b1);
tlo.add(Box.createRigidArea(new Dimension(0, 45)));
tlo.add(b2);
tlo.add(Box.createRigidArea(new Dimension(0, 45)));
//tlo.add(b3);
//tlo.add(Box.createRigidArea(new Dimension(0, 25)));
tlo.add(b4);
tlo.add(Box.createRigidArea(new Dimension(0, 45)));
tlo.add(b5);
//ustawia marginesy na przyciskach na 0:
b1.setMargin(new Insets(0,0,0,0));
b2.setMargin(new Insets(0,0,0,0));
//b3.setMargin(new Insets(0,0,0,0));
b4.setMargin(new Insets(0,0,0,0));
b5.setMargin(new Insets(0,0,0,0));
//ustawia czarna ramke na przyciskach:
b1.setBorder(BorderFactory.createLineBorder(Color.BLACK));
b2.setBorder(BorderFactory.createLineBorder(Color.BLACK));
//b3.setBorder(BorderFactory.createLineBorder(Color.BLACK));
b4.setBorder(BorderFactory.createLineBorder(Color.BLACK));
b5.setBorder(BorderFactory.createLineBorder(Color.BLACK));
//wczytanie zapisanych opcji z pliku:
try
{
BufferedReader br = new BufferedReader(new FileReader("opcje.txt"));
Main.level = Integer.parseInt(br.readLine());
Main.punkty = Integer.parseInt(br.readLine());
Main.tlo = Integer.parseInt(br.readLine());
}
catch(IOException ex){
System.err.print("DUPA EXCEPTION !!!!");
}
//nasluchiwacze anionimowe:
b1.addActionListener(new ActionListener () //graj
{
public void actionPerformed(ActionEvent e)
{
Main.newgame1 = new NewGame(Main.level, Main.tlo, Main.punkty);
Main.newgame1.setVisible(true);
Main.newgame1.setLocation(getLocation());
setVisible(false);
}
}
);
b2.addActionListener(new ActionListener () //jak grac
{
public void actionPerformed(ActionEvent e)
{
Main.howto1.setVisible(true);
Main.howto1.setLocation(getLocation());
setVisible(false);
}
}
);
/*b3.addActionListener(new ActionListener () //wyniki
{
public void actionPerformed(ActionEvent e)
{
Main.highscores1.setVisible(true);
Main.highscores1.setLocation(getLocation());
setVisible(false);
}
}
);*/
b4.addActionListener(new ActionListener () //opcje
{
public void actionPerformed(ActionEvent e)
{
Main.options1.setVisible(true);
Main.options1.setLocation(getLocation());
setVisible(false);
}
}
);
b5.addActionListener(new ActionListener () //koniec
{
public void actionPerformed(ActionEvent e)
{
System.exit(0);
}
}
);
setSize(800,600);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setVisible(true);
setResizable(false);
}
} |