problem for games

i am trying to make a game .Now i am starting form game menu,but it isn't work.

import java.awt.event.*;

import javax.swing.*;

import java.awt.*;

public class GameMenu extends JFrame implements MouseListener

{

ImageIcon icon;

Image image;

ImageIcon icon2;

JList menulist;

GameMenu frame;

public GameMenu(){

//Create background

icon = new ImageIcon("image/bgimg.jpg");

icon2 = new ImageIcon("image/002.jpg");

JPanel panel = new JPanel(new GridBagLayout())

{

protected void paintComponent(Graphics g)

{

// Dispaly image at at full size

g.drawImage(icon.getImage(), 0, 0, null);

g.drawImage(icon2.getImage(), 0, 10, null);

super.paintComponent(g);

}

};

GridBagConstraints a = new GridBagConstraints();

//create menulist

//Feild

String[] gameMenulist = {"New Game","Abouts","how to play","Options","Exit"};

menulist= new JList(gameMenulist);

ListSelectionModel menulistModel = menulist.getSelectionModel();

//menulist setting

menulist.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);

menulist.setLayoutOrientation(JList.HORIZONTAL_WRAP);

menulist.setVisibleRowCount(-1);

menulist.setBackground(Color.BLACK);

menulist.setForeground(Color.WHITE);

menulist.addMouseListener(this);

panel.add(menulist, a);

panel.setOpaque( false );

panel.setPreferredSize( new Dimension(400, 400) );

getContentPane().add(panel);

}

public void mouseClicked(MouseEvent e) {

switch(menulist.getSelectedIndex()){

case 0:

frame.setSize(300,300);

case 1:

frame.setSize(600,600);

}

}

public void createGUI(){

frame = new GameMenu();

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

frame.setSize(600, 600);

frame.setLocationRelativeTo( null );

frame.setVisible(true);

}

public static void main(String [] args){

createGUI();

}

}

[2092 byte] By [nickgoldgodla] at [2007-11-27 3:48:49]
# 1

import java.awt.event.*;

import javax.swing.*;

import java.awt.*;

public class GM extends JFrame implements MouseListener {

ImageIcon icon;

//Image image;

ImageIcon icon2;

JList menulist;

public GM() {

//Create background

icon = new ImageIcon("image/bgimg.jpg");

//"images/Bird.gif");

icon2 = new ImageIcon("image/002.jpg");

//"images/Rabbit.gif");

JPanel panel = new JPanel(new GridBagLayout()) {

protected void paintComponent(Graphics g) {

// This next statement tells this (panel) to

// draw its default background. Do it first.

super.paintComponent(g);

// Dispaly image at at full size

g.drawImage(icon.getImage(), 0, 0, null);

g.drawImage(icon2.getImage(), 100, 100, null);

}

};

GridBagConstraints a = new GridBagConstraints();

//create menulist

//Feild

String[] gameMenulist = {"New Game","Abouts","how to play","Options","Exit"};

menulist= new JList(gameMenulist);

ListSelectionModel menulistModel = menulist.getSelectionModel();

//menulist setting

menulist.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);

menulist.setLayoutOrientation(JList.HORIZONTAL_WRAP);

menulist.setVisibleRowCount(-1);

menulist.setBackground(Color.BLACK);

menulist.setForeground(Color.WHITE);

menulist.addMouseListener(this);

panel.add(menulist, a);

panel.setOpaque( false );

// This call to setPreferredSize will have no affect when

// you add panel to the center of a BorderLayout. To see why

// comment-out the line above and un-comment this next line.

//panel.setBackground(Color.pink);

panel.setPreferredSize( new Dimension(400, 400) );

getContentPane().add(panel);

}

public void mouseClicked(MouseEvent e) {

switch(menulist.getSelectedIndex()) {

case 0:

setSize(300,300);

break;

case 1:

setSize(600,600);

}

// You can change the size but to tell the JFrame to

// make the change we must use this Container method.

validate();

}

// These method declarations are required.

// Why? Because the enclosing class implements the

// MouseListener interface. You must provide an

// implementation of every method defined in an

// inteface when you implement it (the interface).

public void mouseEntered(MouseEvent e) {}

public void mouseExited(MouseEvent e) {}

public void mousePressed(MouseEvent e) {}

public void mouseReleased(MouseEvent e) {}

private void createGUI() {

// The enclosing class is a JFrame by virtue of extension.

// So you can call its methods without an instance variable.

setDefaultCloseOperation(EXIT_ON_CLOSE);

setSize(600, 600);

setLocationRelativeTo( null );

setVisible(true);

}

public static void main(String[] args) {

GM app = new GM();

app.createGUI();

}

}

crwooda at 2007-7-12 8:52:42 > top of Java-index,Security,Cryptography...
# 2
thanks a lot ~it's work now~
nickgoldgodla at 2007-7-12 8:52:42 > top of Java-index,Security,Cryptography...