Results 1 to 5 of 5
Thread: problem mastermind
- 03-16-2011, 04:57 PM #1
Member
- Join Date
- Nov 2010
- Posts
- 3
- Rep Power
- 0
problem mastermind
Hello guys ,
I have to make a mastermind game for school but I've some problem doing that .
The problem is that if I click on the buttons that I want to use for making the guess nothing happens . Below I will post the classes that are used tot do the view .
anyone have a suggestion ?
Greetings
PHP Code:package View; import Mastermind.Colour; import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.io.FileNotFoundException; import java.io.FileReader; import java.util.Scanner; /** * author: Alexander Coopmans * version: 1.0 4/03/11 12:35 */ public class Panels extends JFrame{ private final Color[] colors = { Color.RED, Color.GREEN, Color.BLUE, Color.YELLOW, Color.orange,Color.pink, Color.BLACK,new Color(163,73,164),new Color(185,122,87),Color.WHITE,getBackground()}; private JMenuBar mbar; private JButton check; private Colour [] feedb; private Colour [] keuze; private JMenuItem mnew; private JMenuItem mninst; private JMenuItem mninfo; private JMenuItem mnhigh; private JMenuItem mnload; private JMenuItem mnexit; private JMenu mngame; private JMenu mnhelp; public Panels() throws HeadlessException { initialiseerComponenten(); menu(); maakEventHandlers(); toonFrame(); } private void initialiseerComponenten() { keuze = new Colour[4]; feedb=new Colour[4]; check=new JButton("Check"); mbar=new JMenuBar(); mngame=new JMenu("Game "); mnhelp=new JMenu("Help "); mninst=new JMenuItem("Read Instructions "); mninfo=new JMenuItem("Info "); mnew=new JMenuItem("New game"); mnhigh=new JMenuItem(" View Highscore"); mnload=new JMenuItem("Load Game"); mnexit=new JMenuItem("Exit"); } private void layoutComponenten() { JPanel mainframe=new JPanel(new GridLayout(1,2)); JPanel kleuren = new JPanel(new GridLayout(10,4)); JPanel allekleuren = new JPanel(new GridLayout(2,9)); JPanel feedback = new JPanel(new GridLayout(10,4)); for(int j=0;j<10;j++){ for(int i=0;i< 4 ;i++){ kleuren.add(this.keuze[i] = new Colour(getBackground(), 0, 0, 25)); feedback.add(this.feedb[i]=new Colour(getBackground(),0,0,12)).setEnabled(false); } } for (int i=0;i<colors.length;i++) { TransferHandler transfer = new TransferHandler("text"); keuze[0].setTransferHandler(transfer); allekleuren.add(new Colour(colors[i], 0, 0, 25)).addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent me) { } }); } allekleuren.add(check,BorderLayout.SOUTH); kleuren.setSize(500, 400); add(allekleuren, BorderLayout.SOUTH); mainframe.add(kleuren); mainframe.add(feedback); add(mainframe); } private void menu() { mbar.add( mngame); mngame.add(mnew); mngame.addSeparator(); mngame.add(mnhigh); mngame.add(mnload); mngame.add(mnexit); mbar.add(mnhelp); mnhelp.add(mninst); mnhelp.add(mninfo); setJMenuBar(mbar); } private void maakEventHandlers() { mnew.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { new PopupScreen(); layoutComponenten(); toonFrame(); } }); mnhigh.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { // show score } }); mnload.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { // load game } }); mnexit.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { System.exit(0); } }); mninst.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { try { Scanner scanner = new Scanner(new FileReader("instructions.txt")); while (scanner.hasNext()){ String string = scanner.nextLine(); JOptionPane.showMessageDialog(null, string + "\n", "Instructies: ", JOptionPane.INFORMATION_MESSAGE); } scanner.close(); } catch (FileNotFoundException ea) { System.out.println(" bestand instructions.txt niet gevonden!"); } } }); mninfo.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { new SplashScreen(); } }); check.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { // hier kijken de code die ingegeven werd controleren } }); } private void toonFrame() { setTitle("** Mastermind **"); setPreferredSize(new Dimension(439, 498)); setMinimumSize(new Dimension(439,389)); // setResizable(false); //setExtendedState(JFrame.MAXIMIZED_BOTH); this.setDefaultCloseOperation(EXIT_ON_CLOSE); this.setVisible(true); } } package Mastermind; import javax.swing.*; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; /** * Created by IntelliJ IDEA. * User: Nick Weymiens en Alexander Coopmans * Date: 18/02/11 * Time: 11:50 * To change this template use File | Settings | File Templates. */ public class Colour extends JButton { private Color color; public enum Colours {RED,GREEN,YELLOW,BLUE,PURPLE,ORANGE,BROWN,PINK,BLANK,WHITE, BLACK} // used for model side private int x,y,size; public Colour(Color color, int x, int y, int size) { this.color = color; this.x = x; this.y = y; this.size = size; super.setBorder(null); super.setBackground(Color.WHITE); super.setOpaque(true); final Color kleur=color; this.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { System.out.println("geklikt op" +kleur); setColor(kleur); } }); } @Override protected void paintComponent(Graphics g) { super.paintComponent(g); g.setColor(color); g.fillOval(x, y, size, size); } public void setColor(Color color) { this.color = color; } public Color getColor() { return color; } }
- 03-16-2011, 05:00 PM #2
That's way too much code for the question- instead, try narrowing your problem down to an SSCCE.
But here's a question- when are you adding your ActionListener to the button? What does that ActionListener do?How to Ask Questions the Smart Way
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
- 03-16-2011, 05:03 PM #3
This code may be causing problems:
I think it overrides the action listener you assign in the Colour constructor.Java Code:allekleuren.add(new Colour(colors[i], 0, 0, 25)).addMouseListener(new MouseAdapter() { @Override public void mousePressed(MouseEvent me) { } });
- 03-16-2011, 05:07 PM #4
How to Ask Questions the Smart Way
Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!
- 03-16-2011, 05:08 PM #5
Member
- Join Date
- Nov 2010
- Posts
- 3
- Rep Power
- 0
Similar Threads
-
MasterMind Assignement , Use of String Class
By Ebayer in forum New To JavaReplies: 2Last Post: 03-14-2011, 06:23 PM -
Mastermind!
By MishkaRX in forum New To JavaReplies: 11Last Post: 12-14-2010, 01:39 PM -
MasterMind Problem!!
By papinhio in forum New To JavaReplies: 4Last Post: 07-09-2010, 03:51 PM -
how to make mastermind game
By javabeginer in forum New To JavaReplies: 10Last Post: 04-14-2009, 02:11 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks