Page 2 of 2 FirstFirst 12
Results 21 to 39 of 39
Like Tree2Likes

Thread: Double-buffering and mouse=event help please

  1. #21
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,453
    Rep Power
    25

    Default Re: Double-buffering and mouse=event help please

    Is there any way to keep classAppBoard in its own class?
    It is currently in its own class. What does this question mean?
    What happened when you changed the extends JApplet to extends JPanel?

  2. #22
    Parkournerd is offline Member
    Join Date
    Jan 2012
    Posts
    20
    Rep Power
    0

    Default Re: Double-buffering and mouse=event help please

    It does not show up when I launch proChess. It's just a blank, not even different from the background. what I want is to put the classAppBoard inside of proChess. I'm going to be using mouse, audio, and double-buffering if that is relevant

  3. #23
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Double-buffering and mouse=event help please

    You're still showing us your attempt to solve this using an applet, despite our telling you repeatedly that this is wrong. You're still not showing us your attempt to do this with a JPanel. Also, your code should have no static anything other than a main method, but I'm a little reluctant to give any more recommendations since they seem to be ignored. :(

  4. #24
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,453
    Rep Power
    25

    Default Re: Double-buffering and mouse=event help please

    Do you get any error messages?
    Did you put some println statements in the methods in the ClassAppBoard class?
    Did any of them print out?

  5. #25
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Double-buffering and mouse=event help please

    The two programs that you've posted, classAppBoard and proChess, appear to be completely dissimilar in style and content suggesting different authors, and that you may be using borrowed code. If so, I strongly urge you not to do this but to instead use borrowed ideas, sure, but you're own code.

  6. #26
    Parkournerd is offline Member
    Join Date
    Jan 2012
    Posts
    20
    Rep Power
    0

    Default Re: Double-buffering and mouse=event help please

    I tried JPanel, but what else do you need to do after that? Plus, if I make them all non-static methods, will the two classes be able to share the variables?

  7. #27
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Double-buffering and mouse=event help please

    Quote Originally Posted by Parkournerd View Post
    I tried JPanel, but what else do you need to do after that?
    JPanel is the correct way to go about this. You stated that when you tried it, you had errors, but since we don't see the code nor the errors, we're kind of at an impass.

    Plus, if I make them all non-static methods, will the two classes be able to share the variables?
    You don't want them to share common variables, that's not the Java way. You want to have one class call public methods of the other class to share information or to elicit behavior. Consider going through a decent Java book to learn the basics as it will help you in your both your GUI and non-GUI coding. One decent book to consider is the Head First Java text. Another is "Thinking in Java".

    Also, you're using borrowed code for the Applet class, correct?

  8. #28
    Parkournerd is offline Member
    Join Date
    Jan 2012
    Posts
    20
    Rep Power
    0

    Default Re: Double-buffering and mouse=event help please

    What do you mean borrowed code? I just looked the stuff up for the mouse and rendering off-screen first. Honestly, I'm just trying what works. I don't understand paint that well at all.

  9. #29
    Parkournerd is offline Member
    Join Date
    Jan 2012
    Posts
    20
    Rep Power
    0

    Default Re: Double-buffering and mouse=event help please

    Should I just move everything from classPanelBoard to the main class?

  10. #30
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Double-buffering and mouse=event help please

    Quote Originally Posted by Parkournerd View Post
    What do you mean borrowed code?
    Most of the code in the Applet-derived class looks like it's not your code that it was downloaded from some site such as this one.

    I just looked the stuff up for the mouse and rendering off-screen first. Honestly, I'm just trying what works. I don't understand paint that well at all.
    You should read some of the Swing tutorials to see how to draw with Swing and how to use Swing JPanels, JFrames, etc... You won't be able to learn it all in a day or week, but should keep progressing if you apply yourself.

  11. #31
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Double-buffering and mouse=event help please

    Quote Originally Posted by Parkournerd View Post
    Should I just move everything from classPanelBoard to the main class?
    No, that would not be a good thing to do.

  12. #32
    Parkournerd is offline Member
    Join Date
    Jan 2012
    Posts
    20
    Rep Power
    0

    Default Re: Double-buffering and mouse=event help please

    Well, I didn't use any tutorials for making chess. I'm taking Java right now, but it's pretty much self-taught. So should I just put newGame() in the JPanel and then call it from the JFrame? That's pretty much the only thing the currently-applet needs from the main class right now. I will be back.

  13. #33
    Parkournerd is offline Member
    Join Date
    Jan 2012
    Posts
    20
    Rep Power
    0

    Default Re: Double-buffering and mouse=event help please

    Here is what I have so far:

    Java Code:
    /*name:
      date: Dec 16 2011
      purpose: proChess*/
    
    import java.applet.Applet;
    import java.awt.*;
    import java.awt.event.*;
    import javax.swing.*;
    
    public class proChess extends JFrame implements ActionListener
    {
    	/**
    	 * 
    	 */
    	private static final long serialVersionUID = 8828135172836094084L;
    	
    	static JFrame frameProChess = new JFrame("ProChess");
    		// all items in window
    		static Panel panelProChess = new Panel();
    			static JLabel iconTitle = new JLabel(createImageIcon("iconLogo.png")); 
    			static Panel panelDisplay = new Panel(new GridLayout(3,1));
    				static JLabel labelPlayer1;
    				static JLabel labelPlayer2;
    				static JLabel labelTurn;
    			static JLabel labelPromotionTitle;
    			static Panel panelChoice = new Panel(new GridLayout(1,4));
    				static JButton buttonChoice1 = new JButton();
    				static JButton buttonChoice2 = new JButton();
    				static JButton buttonChoice3 = new JButton();
    				static JButton buttonChoice4 = new JButton();
    	
    	static JFrame frameHelp = new JFrame("Help");
    	static boolean bolHelp = false;
    	static JFrame frameSetting = new JFrame("Settings");
    	static boolean bolSetting = false;
    
    	public static void main(String[] args) 
    	{
    		@SuppressWarnings("unused")
    		proChess proChess = new proChess();
    	}
    	
    	@SuppressWarnings("deprecation")
    	public proChess()
    	{	
            
    		// Menu
    		JPopupMenu.setDefaultLightWeightPopupEnabled(false);
    		JMenuBar JMenuBar = new JMenuBar();
    		frameProChess.setJMenuBar(JMenuBar);
    			JMenu menuMenu = new JMenu("Menu");
    				JMenuItem itemNewGame = new JMenuItem("New Game");
    				menuMenu.add(itemNewGame);
    				itemNewGame.setActionCommand ("New Game");
    				itemNewGame.addActionListener((ActionListener)this);
    				JMenuItem itemSaveGame = new JMenuItem("Save Game");
    				menuMenu.add(itemSaveGame);
    				itemSaveGame.setActionCommand ("Save Game");
    				itemSaveGame.addActionListener((ActionListener)this);
    				JMenuItem itemLoadGame = new JMenuItem("Load Game");
    				menuMenu.add(itemLoadGame);
    				itemLoadGame.setActionCommand ("Load Game");
    				itemLoadGame.addActionListener((ActionListener)this);
    				JMenuItem itemSetting = new JMenuItem("Settings");
    				itemSetting.setActionCommand ("Settings");
    				itemSetting.addActionListener((ActionListener)this);
    				menuMenu.add(itemSetting);
    				JMenuBar.add(menuMenu);
    			JMenu menuHelp = new JMenu("Help");
    				JMenuItem itemHelp = new JMenuItem("Help");
    				menuHelp.add(itemHelp);
    				itemHelp.setActionCommand ("Help");
    				itemHelp.addActionListener((ActionListener)this);
    				JMenuBar.add(menuHelp);
    		
    		// disable auto layout
    		panelProChess.setLayout(null);
    		
    			/* Not as good on XP
    			 *try 
    			 *{
    			 *	UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
    			 *}catch(Exception e){}
    			 */
    			 
    		iconTitle = new JLabel(createImageIcon("iconLogo.png"));
    		
    		classPanelBoard panelBoard = new classPanelBoard();
    		
    		labelPlayer2 = new JLabel("<html><u>Player 2</u><br><br>Time:<br>Gold:<br>Score:</html>");
    		panelDisplay.add(labelPlayer2);			
    		labelPlayer1 = new JLabel("<html><u>Player 1</u><br><br>Time:<br>Gold:<br>Score:</html>");
    		panelDisplay.add(labelPlayer1);
    		labelTurn = new JLabel("It is Player 1's turn.");
    		panelDisplay.add(labelTurn);
    
    		// Segment Three
    		labelPromotionTitle = new JLabel("<html><u>Promotion</u></html>");
    
    		buttonChoice1 = new JButton();
    		panelChoice.add(buttonChoice1);
    		buttonChoice2 = new JButton();
    		panelChoice.add(buttonChoice2);
    		buttonChoice3 = new JButton();
    		panelChoice.add(buttonChoice3);
    		buttonChoice4 = new JButton();
    		panelChoice.add(buttonChoice4);
    
    		panelProChess.add(iconTitle);
    		iconTitle.setBounds(15,15,484,107);
    		panelProChess.add(panelBoard);
    		panelBoard.setBounds(15,122,480,480);
    		panelProChess.add(panelDisplay);
    		panelDisplay.setBounds(514,0,254,768);
    		panelProChess.add(labelPromotionTitle);
    		labelPromotionTitle.setBounds(225,621,63,18);
    		panelProChess.add(panelChoice);
    		panelChoice.setBounds(135,653,242,60);
    
    		frameProChess.add(panelProChess);
    		
    		frameProChess.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    		frameProChess.pack();
    		frameProChess.resize(768,768);
    		frameProChess.setLocationRelativeTo(null);
    		frameProChess.setResizable(false);
    		frameProChess.setVisible(true);
    	}
    	public void saveGame()
    	{
    
    	}
    	public void loadGame()
    	{
    		
    	}
    	public void actionPerformed(ActionEvent e) 
    	{
    			if(e.getActionCommand().equals ("New Game"))
    			{
    			}
    			if(e.getActionCommand().equals ("Save Game"))
    			{
    				saveGame();
    			}
    			if(e.getActionCommand().equals ("Load Game"))
    			{
    				loadGame();
    			}			
    			if(e.getActionCommand().equals ("Help"))
    			{
    					if(frameHelp.isVisible() == false && bolHelp == false)
    					{
    						bolHelp = true;						
    						@SuppressWarnings("unused")
    						JFrame FrameHelp = new classFrameHelp();
    					}
    					else
    						frameHelp.setVisible(true);
    			}
    			if(e.getActionCommand().equals ("Settings"))
    			{
    					if(frameSetting.isVisible() == false && bolSetting == false)
    					{
    						bolSetting = true;
    						@SuppressWarnings("unused")
    						JFrame FrameSettings = new classFrameSettings();
    					}
    					else 
    						frameSetting.setVisible(true);
    			}
    	}
    	protected static ImageIcon createImageIcon (String path)
    	{
    		java.net.URL imgURL = proChess.class.getResource (path);
    		
    			if (imgURL != null)
    			{
    				return new ImageIcon (imgURL);
    			}
    			else
    			{
    				System.err.println ("Couldn't find file: " + path);
    				return null;
    			}
    	}
    }
    Java Code:
    // import JPanel
    import javax.swing.JPanel;
    // import swing
    import java.awt.*;
    import java.awt.event.*;
    // import java2d
    import java.awt.geom.Point2D;
    // import sound
    import java.applet.AudioClip;
    // import IO
    import java.io.File;
    import java.net.MalformedURLException;    
    
    /*  java.io.File file = new java.io.File("bark.aiff");
        AudioClip sound = Applet.newAudioClip(file.toURL());
        sound.play();*/
    
    public class classPanelBoard extends JPanel implements ActionListener, MouseListener, MouseMotionListener
    {
    	/**
    	 * 
    	 */
    	private static final long serialVersionUID = -4529456824050911554L;
    	
    	Color colorOne = Color.white;
    	Color colorTwo = Color.black;
    	
    	Color colorPieceOne = Color.blue;
    	Color colorPieceTwo = Color.green;
    	Color colorAlpha = new Color(0,0,0,0);
    	
    	String[][] position = new String[8][8];
    	Boolean[][] positionChosen = new Boolean[8][8];
    	Boolean[][] positionMove = new Boolean[8][8];
    	
    	int turn;
    	int[] time = new int[2];
    	int[] gold = new int[2];
    	int[] score = new int[2];
    	
    	int timeSet = 600;
    
        Graphics bufferGraphics = null; 
        Image offscreen = null; 
        
        int curX, curY;
        
        @SuppressWarnings("deprecation")
    	public void init()  
        {         
        	addMouseListener(this);
     	    addMouseMotionListener(this);
     	    newGame(); 
        	resize(480,480);
    
            offscreen = createImage(768,768); 
            bufferGraphics = offscreen.getGraphics();
            newGame();
            repaint();
        }
    	public void newGame()
    	{
    			// reset board
    			for(int y = 0; y < 8; y++)
    			{
    					for(int x = 0; x < 8; x++)
    					{
    						position[x][y] = "      ";
    						positionChosen[x][y] = false;
    						positionMove[x][y] = false;
    					}
    			}
    			
    		// positions pawns for black
    		int y = 1;
    		
    			for(int x = 0; x < 8; x++)
    			{
    				position[x][y] = "bp0000";
    			}
    			
    		// positions pawns for white
    		y = 6;
    			
    			for(int x = 0; x < 8; x++)
    			{
    				position[x][y] = "wp0000";
    			}
    			
    		// positions pieces for black
    		position[0][0] = "br";
    		position[1][0] = "bk";
    		position[2][0] = "bb";
    		position[3][0] = "bq";
    		position[4][0] = "bw";
    		position[5][0] = "bb";
    		position[6][0] = "bk";
    		position[7][0] = "br";
    		
    		// positions pieces for white	
    		position[0][7] = "wr";
    		position[1][7] = "wk";
    		position[2][7] = "wb";
    		position[3][7] = "wq";
    		position[4][7] = "ww";
    		position[5][7] = "wb";
    		position[6][7] = "wk";
    		position[7][7] = "wr";
    		
    		turn = 1;
    		
    			for(int x = 0; x < 2; x++)
    			{
    				time[x] = timeSet;
    				gold[x] = 0;
    				score[x] = 0;
    			}
    	}
        public void paint(Graphics g)  
        {
        	 bufferGraphics.clearRect(0,0,768,768); 
        	 
    			for(int y = 0; y < 8; y++)
    			{
    					for(int x = 0; x < 8; x++)
    					{
    
    						Graphics2D g2 = (Graphics2D) bufferGraphics;
    						g2.setStroke(new BasicStroke(4));
    						
    							if(x % 2 == 1 && y % 2 == 1 || x % 2 == 0 && y % 2 == 0)
    							{
    								bufferGraphics.setColor(colorOne);
    								bufferGraphics.fillRect(x*60,y*60,60,60);
    							}
    							else
    							{
    								bufferGraphics.setColor(colorTwo);
    								bufferGraphics.fillRect(x*60,y*60,60,60);
    							}
    							
    							// draw circles
    							if(position[x][y].charAt(0) == 'b')
    							{
    								((Graphics2D) bufferGraphics).setPaint(generateGradient(colorPieceOne,x,y));
    								bufferGraphics.fillOval(x*60+5,y*60+5,50,50);
    							}
    							else if(position[x][y].charAt(0) == 'w')
    							{
    								((Graphics2D) bufferGraphics).setPaint(generateGradient(colorPieceTwo,x,y));
    								bufferGraphics.fillOval(x*60+5,y*60+5,50,50);
    							}
    							
    							bufferGraphics.setColor(Color.black);
    						
    							// draw pawns
    							if(position[x][y].charAt(1) == 'p')
    							{
    									if(position[x][y].charAt(0) == 'b')
    									{
    										bufferGraphics.setColor(Color.white);
    										bufferGraphics.fillRect(x*60+29,y*60+30,4,20);
    										bufferGraphics.setColor(Color.black);
    										bufferGraphics.drawLine(x*60+30,y*60+30,x*60+16,y*60+44);
    										bufferGraphics.drawLine(x*60+31,y*60+30,x*60+44,y*60+44);
    									}
    									else
    									{
    										bufferGraphics.setColor(Color.white);
    										bufferGraphics.fillRect(x*60+29,y*60+10,4,20);
    										bufferGraphics.setColor(Color.black);
    										bufferGraphics.drawLine(x*60+30,y*60+30,x*60+16,y*60+16);
    										bufferGraphics.drawLine(x*60+31,y*60+30,x*60+44,y*60+16);
    									}
    									
    									if(position[x][y].charAt(2) == '1')
    									{
    										bufferGraphics.fillRect(x*60+28,y*60+10,4,40);
    										bufferGraphics.fillRect(x*60+10,y*60+28,40,4);
    									}
    									if(position[x][y].charAt(3) == '1')
    									{
    										bufferGraphics.drawLine(x*60+15,y*60+15,x*60+45,y*60+45);
    										bufferGraphics.drawLine(x*60+45,y*60+15,x*60+15,y*60+45);
    									}
    									if(position[x][y].charAt(4) == '1')
    									{
    										bufferGraphics.fillRect(x*60+28,y*60+20,4,20);
    										bufferGraphics.fillRect(x*60+20,y*60+28,20,4);
    										bufferGraphics.fillRect(x*60+16,y*60+10,4,40);
    										bufferGraphics.fillRect(x*60+40,y*60+10,4,40);
    										bufferGraphics.fillRect(x*60+10,y*60+16,40,4);
    										bufferGraphics.fillRect(x*60+10,y*60+40,40,4);
    									}
    									if(position[x][y].charAt(5) == '1')
    									{
    										bufferGraphics.fillRect(x*60+28,y*60+20,4,20);
    										bufferGraphics.fillRect(x*60+20,y*60+28,20,4);
    										bufferGraphics.drawLine(x*60+22,y*60+22,x*60+38,y*60+38);
    										bufferGraphics.drawLine(x*60+38,y*60+22,x*60+22,y*60+38);
    										
    										/* TOO BIG
    										 * g.drawLine(x*60+20,y*60+20,x*60+40,y*60+40);
    										 * g.drawLine(x*60+40,y*60+20,x*60+20,y*60+40);*/
    									}	
    							}
    							
    							// draw rooks
    							if(position[x][y].charAt(1) == 'r')
    							{
    								bufferGraphics.fillRect(x*60+28,y*60+10,4,40);
    								bufferGraphics.fillRect(x*60+10,y*60+28,40,4);
    							}
    							// draw knights
    							if(position[x][y].charAt(1) == 'k')
    							{
    								bufferGraphics.fillRect(x*60+28,y*60+20,4,20);
    								bufferGraphics.fillRect(x*60+20,y*60+28,20,4);
    								bufferGraphics.fillRect(x*60+16,y*60+10,4,40);
    								bufferGraphics.fillRect(x*60+40,y*60+10,4,40);
    								bufferGraphics.fillRect(x*60+10,y*60+16,40,4);
    								bufferGraphics.fillRect(x*60+10,y*60+40,40,4);
    							}
    							// draw bishops
    							if(position[x][y].charAt(1) == 'b')
    							{
    								bufferGraphics.drawLine(x*60+15,y*60+15,x*60+45,y*60+45);
    								bufferGraphics.drawLine(x*60+45,y*60+15,x*60+15,y*60+45);
    							}
    							// draw queens
    							if(position[x][y].charAt(1) == 'q')
    							{
    								bufferGraphics.fillRect(x*60+28,y*60+10,4,40);
    								bufferGraphics.fillRect(x*60+10,y*60+28,40,4);
    								bufferGraphics.drawLine(x*60+15,y*60+15,x*60+45,y*60+45);
    								bufferGraphics.drawLine(x*60+45,y*60+15,x*60+15,y*60+45);
    							}
    							// draw kings
    							if(position[x][y].charAt(1) == 'w')
    							{
    								bufferGraphics.fillRect(x*60+28,y*60+20,4,20);
    								bufferGraphics.fillRect(x*60+20,y*60+28,20,4);
    								bufferGraphics.drawLine(x*60+22,y*60+22,x*60+38,y*60+38);
    								bufferGraphics.drawLine(x*60+38,y*60+22,x*60+22,y*60+38);
    							}
    							
    							// highlight chosen square
    							if(positionChosen[x][y] == true)
    							{
    								((Graphics2D) bufferGraphics).setPaint(generateRadialGradient(Color.orange,x,y));
    								bufferGraphics.fillOval(x*60-10,y*60-10,90,90);
    							}
    							// highlight available moves
    							if(positionMove[x][y] == true)
    							{
    								((Graphics2D) bufferGraphics).setPaint(generateRadialGradient(Color.red,x,y));
    								bufferGraphics.fillOval(x*60,y*60,60,60);
    							}
    					}		
    			}
             // draw the offscreen image to the screen like a normal image. 
             // Since offscreen is the screen width we start at 0,0. 
             g.drawImage(offscreen,0,0,this); 
        }
        public void update(Graphics g) 
        { 
             paint(g); 
        } 
        public GradientPaint generateGradient(Color c, int x,int y)
        {
        	GradientPaint gradient = new GradientPaint(x*60+5,y*60+5,c,x*60+30,y*60+30,Color.gray,true);
    		return gradient;
        }
        public RadialGradientPaint generateRadialGradient(Color c, int x,int y)
        {
        	Point2D center = new Point2D.Float(x*60+30, y*60+30);
            float radius = 30;
            float[] dist = {0.0f, 1f};
            Color[] colors = {c, colorAlpha};
        	RadialGradientPaint gradient = new RadialGradientPaint(center, radius, dist, colors);
    		return gradient;
        }
    	public void generateHighlightMoves(int x1, int y1, String p)
    	{
    		positionChosen[x1][y1] = true;
    		
    			for(int y = 0; y < 8; y++)
    			{
    					for(int x = 0; x < 8; x++)
    					{
    						positionMove[x][y] = false;			
    					}
    			}
    			
    			if(position[x1][y1].charAt(1) == 'p')
    			{
    					if(position[x1][y1].charAt(0) == 'b')
    					{
    							if(y1==1 && y1+1<8)
    							{
    								positionMove[x1][y1+1] = true;
    								
    									if(position[x1][y1+2].equals("      ") && y1+2<8)
    									{
    										positionMove[x1][y1+2] = true;	
    									}
    							}
    					}
    					if(position[x1][y1].charAt(0) == 'w')
    					{
    							if(y1==6 && y1-1>-1)
    							{
    								positionMove[x1][y1-1] = true;
    					
    									if(position[x1][y1-2].equals("      ") && y1-2>-1)
    									{
    										positionMove[x1][y1-2] = true;	
    									}				
    							}
    					}
    			}
    			if(position[x1][y1].charAt(1) == 'r' || position[x1][y1].charAt(1) == 'p' && position[x1][y1].charAt(2) == '1')
    			{
    				
    			}
    			if(position[x1][y1].charAt(1) == 'k' || position[x1][y1].charAt(1) == 'p' && position[x1][y1].charAt(4) == '1')
    			{
    				
    			}
    			if(position[x1][y1].charAt(1) == 'b' || position[x1][y1].charAt(1) == 'p' && position[x1][y1].charAt(3) == '1')
    			{
    				
    			}
    			if(position[x1][y1].charAt(1) == 'q')
    			{
    				
    			}
    			if(position[x1][y1].charAt(1) == 'w' || position[x1][y1].charAt(1) == 'p' && position[x1][y1].charAt(5) == '1')
    			{
    					if(y1-1>-1)
    					{
    						positionMove[x1][y1-1] = true;
    					}
    					if(y1+1<8)
    					{
    						positionMove[x1][y1+1] = true;
    					}
    					if(x1-1>-1)
    					{
    						positionMove[x1-1][y1] = true;
    					}	
    					if(x1+1<8)
    					{
    						positionMove[x1+1][y1] = true;
    					}
    					if(x1-1>-1 && y1-1>-1)
    					{
    						positionMove[x1-1][y1-1] = true;
    					}
    					if(x1+1<8 && y1-1>-1)
    					{
    						positionMove[x1+1][y1-1] = true;
    					}
    					if(x1-1>-1 && y1+1<8)
    					{
    						positionMove[x1-1][y1+1] = true;
    					}
    					if(x1+1<8 && y1+1<8)
    					{
    						positionMove[x1+1][y1+1] = true;
    					}	
    			}
    	}	
    	public void actionPerformed(ActionEvent e) 
    	{
    		// TODO Auto-generated method stub
    	}
    	public void mouseClicked(MouseEvent e) 
    	{
    			for(int y = 0; y < 8; y++)
    			{
    					for(int x = 0; x < 8; x++)
    					{
    						positionChosen[x][y] = false;
    					}
    			}
    		
    		int x1 = (int)(e.getX()/60);
    		int y1 = (int)(e.getY()/60);
    		
    		generateHighlightMoves(x1, y1, position[x1][y1]);
    		
    		repaint();
    	}		
    	public void mousePressed(MouseEvent e) 
    	{
    		// TODO Auto-generated method stub
    	}	
    	public void mouseReleased(MouseEvent e) 
    	{
    		// TODO Auto-generated method stub
    	}
    	public void mouseDragged(MouseEvent e) 
    	{
    		// TODO Auto-generated method stub
    	}
    	public void mouseMoved(MouseEvent e) 
    	{
    		// TODO Auto-generated method stub
    	}	
    	public void mouseEntered(MouseEvent e) 
    	{
    		// TODO Auto-generated method stub
    	}
    	public void mouseExited(MouseEvent e) 
    	{
    		// TODO Auto-generated method stub	
    	}
    
    
    	
    }
    Errors:

    Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    at classPanelBoard.paint(classPanelBoard.java:121)
    at java.awt.GraphicsCallback$PaintCallback.run(Unknow n Source)
    at sun.awt.SunGraphicsCallback.runOneComponent(Unknow n Source)
    at sun.awt.SunGraphicsCallback.runComponents(Unknown Source)
    at java.awt.Container.paint(Unknown Source)
    at sun.awt.RepaintArea.paintComponent(Unknown Source)
    at sun.awt.RepaintArea.paint(Unknown Source)
    at sun.awt.windows.WComponentPeer.handleEvent(Unknown Source)
    at java.awt.Component.dispatchEventImpl(Unknown Source)
    at java.awt.Container.dispatchEventImpl(Unknown Source)
    at java.awt.Component.dispatchEvent(Unknown Source)
    at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
    at java.awt.EventQueue.access$000(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.awt.EventQueue$3.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPri vilege(Unknown Source)
    at java.security.ProtectionDomain$1.doIntersectionPri vilege(Unknown Source)
    at java.awt.EventQueue$4.run(Unknown Source)
    at java.awt.EventQueue$4.run(Unknown Source)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.security.ProtectionDomain$1.doIntersectionPri vilege(Unknown Source)
    at java.awt.EventQueue.dispatchEvent(Unknown Source)
    at java.awt.EventDispatchThread.pumpOneEventForFilter s(Unknown Source)
    at java.awt.EventDispatchThread.pumpEventsForFilter(U nknown Source)
    at java.awt.EventDispatchThread.pumpEventsForHierarch y(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
    at java.awt.EventDispatchThread.run(Unknown Source)

    I tried the print-outs. They don't work because the program is stopping at the first paint.
    Last edited by Parkournerd; 01-13-2012 at 03:10 AM.

  14. #34
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Double-buffering and mouse=event help please

    Yeah, you're just copying code from one class to another, changing the super class from Applet to JPanel. That's not going to work. Sigh...

    Go to the tutorials, learn basic Java, then Swing. In other words you'll want to learn to walk first, then run, then fly.

  15. #35
    Parkournerd is offline Member
    Join Date
    Jan 2012
    Posts
    20
    Rep Power
    0

    Default Re: Double-buffering and mouse=event help please

    Could you please help me out on this one? This thing's due in 3 weeks and I'm trying my best. We only learned single-class stuff, JFrames, Applets, loops, etc.

  16. #36
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

    Default Re: Double-buffering and mouse=event help please

    Quote Originally Posted by Parkournerd View Post
    Could you please help me out on this one? This thing's due in 3 weeks and I'm trying my best. We only learned single-class stuff, JFrames, Applets, loops, etc.
    I think that you may be running into the limits of what a forum can and can't do.

    We're quite good at helping explain compiler errors and run-time exceptions and at helping explain concepts and debugging relative straight-forward errors, but your problem as I see it is one of needing to understand some basic concepts and some complex ones including how to create a fairly complex GUI based on multiple classes, and I'm not sure a forum would be able to help you with this.

    Consider first and fore most simplifying what you're doing.
    Consider only using code that only you yourself have written and not borrowing code, especially code that you don't understand since this way leads to pain and frustration.

  17. #37
    Parkournerd is offline Member
    Join Date
    Jan 2012
    Posts
    20
    Rep Power
    0

    Default Re: Double-buffering and mouse=event help please

    But, I actually need the extra code though. I'm taking small pieces of code like buffering, and how to play audio, not anything big at all. All the structure, the poor structure, of the program and logic of the program I did myself. I don't see any problem with that. If you won't help me, could you at least point me to the proper tutorial for setting this up?

  18. #38
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,316
    Blog Entries
    1
    Rep Power
    26

  19. #39
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,453
    Rep Power
    25

    Default Re: Double-buffering and mouse=event help please

    Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException
    at classPanelBoard.paint(classPanelBoard.java:121)
    Have you tried to track down what variable is null and why it is null?

Page 2 of 2 FirstFirst 12

Similar Threads

  1. Double Buffering
    By Macpwnage in forum Java 2D
    Replies: 8
    Last Post: 07-18-2011, 09:17 PM
  2. Help with double Buffering
    By Kyle227 in forum AWT / Swing
    Replies: 1
    Last Post: 10-26-2010, 09:08 PM
  3. Double Buffering an Application?
    By Moncleared in forum New To Java
    Replies: 8
    Last Post: 09-14-2009, 04:45 AM
  4. Double Buffering
    By dunff2k in forum SWT / JFace
    Replies: 1
    Last Post: 11-14-2008, 03:26 PM
  5. Double Buffering problem
    By aprenz in forum Java Applets
    Replies: 0
    Last Post: 05-28-2008, 04:26 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •