|
JVirusFrame |
|
/* * JVirus is a PacMan clone, written in Java. * * Please read "http://jvirus.sourceforge.net/jvirus_licence.txt" for copyrights. * * The sourcecode is designed and created with * Sun J2SDK 1.3 and Microsoft Visual J++ 6.0 * * JVirus homepage: http://jvirus.sourceforge.net * * autor: Slawa Weis * email: slawaweis@animatronik.net * */ package org.game.JVirus; import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.border.*; import org.game.JVirus.res.*; /** * Frame class for the JVirusPanel. JVirus can be a applet, so JVirusFrame is not importand and has no important code. * * @see org.game.JVirus.JVirusPanel */ public class JVirusFrame extends JFrame { /** * for JVirusPanel */ protected JVirusPanel mainPanel = null; /** * Main constructor for JVirusFrame. Simply cal it to create the GUI and start the game. */ public JVirusFrame() { super("JVirus - \"Write once, destroy anywhere\" [version 0.3]"); JVirusInfoScreen is = new JVirusInfoScreen(this); is.setVisible(true); setIconImage(new ImageIcon(Resource.class.getResource("logo32x32.gif")).getImage()); mainPanel = new JVirusPanel(this, is); getContentPane().add(mainPanel); pack(); Dimension screen = Toolkit.getDefaultToolkit().getScreenSize(); setLocation((screen.width - getWidth())/2, (screen.height - getHeight())/2); setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE); setResizable(false); addWindowListener(new JVirusFrame.WindowCloser(this)); setVisible(true); is.setVisible(false); is.addCloser(); // System.out.println("Window Size: " + getSize()); } /** * Infoscreen. Viewing on Start and if the user choose about from help menu. */ public class JVirusInfoScreen extends JWindow { /** * Standart constructor. Creates a JWindow witch a image and two JTextArea. * * @param parent Frame parent */ public JVirusInfoScreen(Frame parent) { super(parent); Dimension screen = Toolkit.getDefaultToolkit().getScreenSize(); setBackground(Color.black); ImageIcon back = new ImageIcon(Resource.class.getResource("startscreen.gif")); setSize(back.getIconWidth(), back.getIconHeight()); setLocation((screen.width - back.getIconWidth())/2, (screen.height - back.getIconHeight())/2); Container contentPane = getContentPane(); contentPane.setLayout(null); String text = "Loading...\n"+ "\n" + "!!! Important Notice !!!\n" + "This virus is a beta, so the e-mailing itself function is not implemented. Please, select 50 of you best friends from you address book and send them this virus. Thanks for you cooperation. You help a little Virus to become big :)." ; String about = "created by:\n" + "Slawa Weis\n" + "slawaweis@animatronik.net\n" + "http://jvirus.sourceforge.net" ; contentPane.add(createTextArea(text, 10, 135, 350, 125, 12, Color.red)); contentPane.add(createTextArea(about, 520, 15, 170, 80, 12, Color.orange)); JLabel back_label = new JLabel(back); back_label.setSize(back.getIconWidth(), back.getIconHeight()); back_label.setLocation(0, 0); contentPane.add(back_label); } /** * add a Closer to Infoscreen after loading of the programm. */ public void addCloser() { addMouseListener(new Closer()); } /** * Closer for Infoscreen. Close it if user clicks with mouse. */ protected class Closer extends MouseAdapter { /** * from MouseAdapter */ public void mouseClicked(MouseEvent e) { setVisible(false); } } /** * Creates a JTextArea for the Infoscreen. Set many Parameters. * * @param text text in JTextArea * @param x x coordinate * @param y y coordinate * @param w width * @param h height * @param fs font size * @param color font color */ protected JTextArea createTextArea(String text, int x, int y, int w, int h, int fs, Color color) { JTextArea jta = new JTextArea(text); jta.setBorder(null); jta.setBackground(Color.black); jta.setForeground(color); jta.setFont(new Font(jta.getFont().getFontName(), Font.PLAIN, fs)); jta.setLineWrap(true); jta.setWrapStyleWord(true); jta.setLocation(x, y); jta.setSize(w, h); return jta; } } /** * Helper class for JVirusFrame to close it. * * @see org.game.JVirus.JVirusFrame */ protected class WindowCloser extends WindowAdapter { /** * the frame to close */ protected JFrame frame = null; /** * Main constructor. * * @param frame parent frame. */ public WindowCloser(JFrame frame) { this.frame = frame; } /** * from WindowAdapter. * * @see java.awt.event.WindowAdapter */ public void windowClosing(WindowEvent e) { // System.out.println("windowClosing"); if(mainPanel.quitGame()) { frame.setVisible(false); frame.dispose(); System.exit(0); } } /* * * from WindowAdapter. * * @see java.awt.event.WindowAdapter */ /* public void windowClosed(WindowEvent e) { System.out.println("windowClosed"); } */ } /////////////////////////////////////////////////////////////////// // JWindow for fullscreen mode /* public class JVirusWindow extends JWindow implements KeyListener { private JPanel mainPanel = null; public JVirusWindow(Frame parent) { super(parent); Dimension screen = Toolkit.getDefaultToolkit().getScreenSize(); this.setSize(screen); this.setLocation(0, 0); this.getContentPane().setLayout(new GridLayout(1, 1)); mainPanel = new JPanel(null); mainPanel.setBackground(Color.black); getContentPane().add(mainPanel); } } */ // JWindow for fullscreen mode /////////////////////////////////////////////////////////////////// }
|
JVirusFrame |
|