Click here to Skip to main content
15,914,163 members
Home / Discussions / Java
   

Java

 
GeneralRe: JML where is the wrong? Pin
williamroma17-Mar-11 2:06
williamroma17-Mar-11 2:06 
GeneralRe: JML where is the wrong? Pin
_Erik_17-Mar-11 3:43
_Erik_17-Mar-11 3:43 
AnswerRe: JML where is the wrong? Pin
TorstenH.16-Mar-11 20:57
TorstenH.16-Mar-11 20:57 
QuestionVoice Recognition for Reading Program Pin
luc53252316-Mar-11 9:03
luc53252316-Mar-11 9:03 
AnswerRe: Voice Recognition for Reading Program Pin
Richard MacCutchan16-Mar-11 12:53
mveRichard MacCutchan16-Mar-11 12:53 
AnswerRe: Voice Recognition for Reading Program Pin
TorstenH.16-Mar-11 21:02
TorstenH.16-Mar-11 21:02 
GeneralRe: Voice Recognition for Reading Program Pin
luc53252317-Mar-11 7:08
luc53252317-Mar-11 7:08 
QuestionEvent Listener problem Pin
kurt114-Mar-11 10:46
kurt114-Mar-11 10:46 
Hi all,
I am writing a small 2D platform game and currently working on EventListeners. When the user clicks the 'blackSquare' JButton it is removed from the screen and placed within a different JPanel (the inventory). However once this event has occoured the player sprite no longer responds to the user input, can anyone help.
package com.brackeen.javagamebook.input;

import com.brackeen.javagamebook.graphics.*;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.border.EtchedBorder;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;

/**
 *
 * @author Kurt
 */

public class InvItems extends MenuScreen implements ActionListener
{  
      public static void main(String[] args)
    {
        new InvItems().run();
    }
    
    private JPanel panelZero;
    private JPanel panelOne;
    private JPanel panelTwo;
    private JPanel panelThree;
    private JPanel panelFour;
    private JPanel panelFive;
    
    private JButton quitButton;
    private JButton blackSquare;
     
    private JTextArea textArea;
    private JLabel inventoryLabel;
    private JList dropDown;
    String [] items ={"Take", "Examine"};
    
    //-------------------------------------------TEXT FOR THE JTEXTAREA------------------------------------------------
    String textOne = ("Text Area");
    String textTwo = ("Its Just a black square");
    //-------------------------------------------END OF TEXT FOR THE JTEXTAREA-----------------------------------------
    
    /** Creates a new instance of InvItems */
     public void init()  
    {
        super.init();
        // make sure Swing components don't paint themselves
        NullRepaintManager.install();
        inventoryLabel = new JLabel("Inventory");
        dropDown = new JList(items);
 
        panelZero = new JPanel();
        panelOne = new JPanel();
        panelTwo = new JPanel();
        panelThree = new JPanel();
        panelFour = new JPanel();
        panelFive = new JPanel();
        
        inventoryLabel.setFont(new Font("Blackadder ITC", Font.ITALIC, 16));
        inventoryLabel.setForeground(Color.RED);
        
        textArea = new JTextArea();
        textArea.setText(textOne);
        textArea.setFont(new Font("Blackadder ITC", Font.ITALIC, 16));
        textArea.setBackground(new Color(0, 0, 0, 0));
        textArea.setForeground(Color.RED);
        panelFive.setBackground(new Color(0, 0, 0, 0));
 
        //--------------------------METHODS FOR ADDING BUTTONS----------------------------------------------------
        
        quitButton = createButton("quit", "Quit"); 
        quitButton.setBounds(50, 50, 64, 64);
        quitButton.setVisible(true);
        
        blackSquare = createButton("test", "Test");
        blackSquare.setVisible(true);
        
        //---------------------START OF FRAME BUILDING METHODS-------------------------------------------------------
        JFrame frame = super.screen.getFullScreenWindow();
        Container contentPane = frame.getContentPane();
        
        Cursor cursor = Cursor.getPredefinedCursor(Cursor.HAND_CURSOR);
        frame.setCursor(cursor);
        
       if (contentPane instanceof JComponent) 
       {
           ((JComponent)contentPane).setOpaque(false);
       }
        //---------------------END OF FRAME BUILDING METHODS-------------------------------------------------------
        
        contentPane.setLayout(null);
        
        panelZero.setBounds(0, 0, 75, 75);
        panelOne.setOpaque(true);
        
        panelOne.setBounds(300, 10, 150, 30);
        panelOne.setOpaque(false);   
        
        panelTwo.setBounds(190,  35, 378, 75);
        panelTwo.setOpaque(false);
        
        panelThree.setBounds(300, 200, 100,  100);
        panelThree.setOpaque(false);
        panelThree.setVisible(true);
        
        panelFour.setBounds(400, 200, 100,  100);
        panelFour.setOpaque(false);
        panelFour.setVisible(false);
         
        panelFive.setBounds(10, 550, 775, 40);
        panelFive.setOpaque(true);
        panelFive.setVisible(true);
        panelFive.setBorder(new EtchedBorder());
        
        panelZero.add(quitButton);
        panelOne.add(inventoryLabel);
       // panelTwo.add(quitButton);
        panelThree.add(blackSquare);
        panelFour.add(dropDown);
        panelFive.add(textArea);
        
        // add components to the screen's content pane
        contentPane.add(panelZero);
        contentPane.add(panelOne);
        contentPane.add(panelTwo);
        contentPane.add(panelThree);
        contentPane.add(panelFour);
        contentPane.add(panelFive);
        
        // explicitly layout components (needed on some systems)
        frame.validate();
        
        blackSquare.addMouseListener(new MouseWatcher());
        dropDown.addMouseListener(new MouseWatcher());
    }
    
    
    public class MouseWatcher extends JFrame implements MouseListener
    {
        public synchronized void mouseClicked(MouseEvent e)
        {            
            panelFour.setVisible(true);  
        }
        public void mouseEntered(MouseEvent e)
        {
           
        }
        public void mouseReleased(MouseEvent e)
        {
        
        }
        public synchronized void mousePressed(MouseEvent e)
        {
            if (dropDown.getSelectedIndex() == 0)
            {
                panelThree.setVisible(false);
                panelTwo.add(blackSquare);
                panelFour.setVisible(false);
            }
            else if (dropDown.getSelectedIndex() == 1)
            {
                textArea.setText(textTwo);
            }
        }
        public void mouseExited(MouseEvent e)
        {
        
        }
    }
    
    // Called by the AWT event dispatch thread when a button is pressed.
    public void actionPerformed(ActionEvent e) 
    {
        Object src = e.getSource();
        if (src == quitButton) 
        {
            super.exit.tap();
        }
    }  
    
    public void draw(Graphics2D g) 
    {
        super.draw(g);
        JFrame frame = super.screen.getFullScreenWindow();

        // the layered pane contains things like popups (tooltips,
        // popup menus) and the content pane.
        frame.getLayeredPane().paintComponents(g);
    }
}

AnswerRe: Event Listener problem Pin
TorstenH.14-Mar-11 23:33
TorstenH.14-Mar-11 23:33 
GeneralRe: Event Listener problem Pin
kurt117-Mar-11 10:38
kurt117-Mar-11 10:38 
GeneralRe: Event Listener problem Pin
kurt119-Mar-11 10:10
kurt119-Mar-11 10:10 
QuestionHtml parser Pin
Aljaz11114-Mar-11 9:10
Aljaz11114-Mar-11 9:10 
AnswerRe: Html parser Pin
Manfred Rudolf Bihy14-Mar-11 12:41
professionalManfred Rudolf Bihy14-Mar-11 12:41 
AnswerRe: Html parser Pin
Luc Pattyn14-Mar-11 13:41
sitebuilderLuc Pattyn14-Mar-11 13:41 
GeneralRe: Html parser Pin
Aljaz11114-Mar-11 13:55
Aljaz11114-Mar-11 13:55 
AnswerRe: Html parser Pin
Luc Pattyn14-Mar-11 14:20
sitebuilderLuc Pattyn14-Mar-11 14:20 
GeneralRe: Html parser [modified] Pin
Aljaz11114-Mar-11 17:33
Aljaz11114-Mar-11 17:33 
AnswerRe: Html parser Pin
all_in_flames8-Jun-11 8:42
professionalall_in_flames8-Jun-11 8:42 
QuestionAction Listener help Pin
mr_plow9914-Mar-11 1:37
mr_plow9914-Mar-11 1:37 
AnswerRe: Action Listener help Pin
Luc Pattyn14-Mar-11 3:28
sitebuilderLuc Pattyn14-Mar-11 3:28 
AnswerRe: Action Listener help Pin
David Skelly14-Mar-11 23:20
David Skelly14-Mar-11 23:20 
GeneralRe: Action Listener help Pin
TorstenH.14-Mar-11 23:35
TorstenH.14-Mar-11 23:35 
Questioninitialization of 3D array in java Pin
gateway2314-Mar-11 0:14
gateway2314-Mar-11 0:14 
AnswerRe: initialization of 3D array in java Pin
Luc Pattyn14-Mar-11 3:31
sitebuilderLuc Pattyn14-Mar-11 3:31 
AnswerRe: initialization of 3D array in java Pin
musefan14-Mar-11 4:23
musefan14-Mar-11 4:23 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.