לוגו אתר Fresh          
 
 
  אפשרות תפריט  ראשי     אפשרות תפריט  צ'אט     אפשרות תפריט  מבזקים     אפשרות תפריט  צור קשר     חץ שמאלה ‎print ‎"Hello World!"; if‎ ‎not rules.‎know ‎then rules.‎read(); חץ ימינה  

לך אחורה   לובי הפורומים > מחשבים > תכנות ובניית אתרים
שמור לעצמך קישור לדף זה באתרי שמירת קישורים חברתיים
תגובה
 
כלי אשכול חפש באשכול זה



  #1  
ישן 16-04-2011, 01:55
  birendorf birendorf אינו מחובר  
 
חבר מתאריך: 02.12.09
הודעות: 19
problem JAVA ActionListener

היי
אני בונה את המשחק איקס עיגול בJAVA, יש לי בעיה עם הactionlistener הוא מחזיר לי שגיאה יש למישהו רעיון תודה מראש לעוזרים... ועוד שאלה איך אני מעלה פה קוד בצורה נורמלית







import java.awt.*;















import java.applet.Applet;


















import java.awt.event.*;


















import javax.swing.*;




















publicclass tic_tac_toe extends JApplet implements ActionListener //,ItemListener


















{




boolean[] empty={true, true,true,true,true,true,true,true,true};

JPanel
panel[] =new JPanel[9];

booleanTwoPlayer= true, startWithRed= true; /// start with red mean the user start to play with red else(false) yellow




















////////////////////////////////////////















JMenuBar bar;




JMenu
game;

JMenu
color;

JMenuItem
p1;

JMenuItem
p2;

JRadioButton
red;

JRadioButton
yellow;



/////////////////////////////////////////




















publicvoid init()

{

addMouseListener(
new myMouseListener());

}

public tic_tac_toe()

{

setLayout(
new GridLayout(3,3,10,10));

for (int l=0; l<9; l++)

{

panel[l]= new JPanel();

add(
panel[l]);

panel[l].setLayout(new BorderLayout());

// panel[l].addContainerListener(null);















}




//////////////////////////////////////////////////////















buildmenu();








}

privatevoid buildmenu()

{

bar= new JMenuBar();

buildgame();

buildcolor();

bar.add(game);

bar.add(color);

setJMenuBar(
bar); ////// why doesn't work i want to add the bar to the JApplet















}






privatevoid buildgame()

{

p1= new JMenuItem("One player");

p1.addActionListener(new PlayerNum()); /////















p2= new JMenuItem("Two player");




p2.addActionListener(new PlayerNum()); /////




















}

privatevoid buildcolor()

{

red= new JRadioButton("Play with red", true);

red.addActionListener(new PlayerNum()); ///// need to add action















yellow= new JRadioButton("Play with yellow");




yellow.addActionListener(new PlayerNum()); ///// need to add action















}




privateclass PlayerNum implements ActionListener ////// action for the menu















{




publicvoid actionPerformed(ActionEvent player)

{

if (p1.isSelected())

TwoPlayer= false;

if (p2.isSelected())

TwoPlayer= true;

if (yellow.isSelected())

startWithRed= false;

if (red.isSelected())

startWithRed= true;

}

}



privateclass myMouseListener extends MouseAdapter //implements ActionListener ///////// panel click















{




publicvoid mousePressed(MouseEvent event)

{

for (int i=0; i<9; i++)

{

if (event.equals(panel[i]))

{

if (empty[i])

{

empty[i]= false;

if (startWithRed)

{

//// draw red















}




}

}

}



}

}









































}




















נערך לאחרונה ע"י birendorf בתאריך 16-04-2011 בשעה 01:58.
תגובה ללא ציטוט תגובה עם ציטוט חזרה לפורום
  #2  
ישן 16-04-2011, 23:08
צלמית המשתמש של בן אור
  בן אור בן אור אינו מחובר  
 
חבר מתאריך: 24.02.05
הודעות: 17,595
שלח הודעה דרך ICQ אל בן אור שלח הודעה דרך MSN אל בן אור Facebook profile Follow me...
בתגובה להודעה מספר 1 שנכתבה על ידי birendorf שמתחילה ב "problem JAVA ActionListener"

ככה שמים כאן קוד (עוטפים בתגית PHP)
קוד PHP:
 import java.awt.*;
import java.applet.Applet;
import java.awt.event.*;
import javax.swing.*;
public class 
tic_tac_toe extends JApplet implements ActionListener //,ItemListener{
    
boolean[] empty={truetrue,true,true,true,true,true,true,true};
    
JPanel panel[] =new JPanel[9];
    
boolean TwoPlayertruestartWithRedtrue/// start with red mean the user start to play with red else(false) yellow
///////////////////////////////////////
    
JMenuBar bar;
    
JMenu game;
    
JMenu color;
    
JMenuItem p1;
    
JMenuItem p2;
    
JRadioButton red;
    
JRadioButton yellow;
/////////////////////////////////////////
    
public void init(){
        
addMouseListener(new myMouseListener());
    }
    public 
tic_tac_toe(){
        
setLayout(new GridLayout(3,3,10,10));
        for (
int l=0l<9l++){
            
panel[l]= new JPanel();
            
add(panel[l]);
            
panel[l].setLayout(new BorderLayout());
            
// panel[l].addContainerListener(null);
        
}
//////////////////////////////////////////////////////
        
buildmenu();
    }
    private 
void buildmenu(){
        
bar= new JMenuBar();
        
buildgame();
        
buildcolor();
        
bar.add(game);
        
bar.add(color);
        
setJMenuBar(bar); ////// why doesn't work i want to add the bar to the JApplet
    
}
    private 
void buildgame(){
        
p1= new JMenuItem("One player");
        
p1.addActionListener(new PlayerNum()); /////
        
p2= new JMenuItem("Two player");
        
p2.addActionListener(new PlayerNum()); /////
    
}
    private 
void buildcolor(){
        
red= new JRadioButton("Play with red"true);
        
red.addActionListener(new PlayerNum()); ///// need to add action
        
yellow= new JRadioButton("Play with yellow");
        
yellow.addActionListener(new PlayerNum()); ///// need to add action
    
}
    private class 
PlayerNum implements ActionListener////// action for the menu{
        
public void actionPerformed(ActionEvent player){
            if (
p1.isSelected())
                
TwoPlayerfalse;

            if (
p2.isSelected())
                
TwoPlayertrue;

            if (
yellow.isSelected())
                
startWithRedfalse;

            if (
red.isSelected())
                
startWithRedtrue;
        }
    }
    private class 
myMouseListener extends MouseAdapter{//implements ActionListener ///////// panel click
        
public void mousePressed(MouseEvent event){
            for (
int i=0i<9i++){
                if (
event.equals(panel[i])){
                    if (empty[
i]){
                        empty[
i]= false;
                        if (
startWithRed){
                            
//// draw red
                        
}
                    }
                }
            }
        }
    }


איזו שגיאה הוא מחזיר לך?
יכול להיות שאתה צריך לממש את actionListener בהגדרה של myMouseListener
_____________________________________
חתימתכם הוסרה כיוון שלא עמדה בחוקי האתר. לפרטים נוספים לחצו כאן. תוכלו לקבל עזרה להתאמת החתימה לחוקים בפורום חתימות וצלמיות.

תגובה ללא ציטוט תגובה עם ציטוט חזרה לפורום
תגובה

כלי אשכול חפש באשכול זה
חפש באשכול זה:

חיפוש מתקדם
מצבי תצוגה דרג אשכול זה
דרג אשכול זה:

מזער את תיבת המידע אפשרויות משלוח הודעות
אתה לא יכול לפתוח אשכולות חדשים
אתה לא יכול להגיב לאשכולות
אתה לא יכול לצרף קבצים
אתה לא יכול לערוך את ההודעות שלך

קוד vB פעיל
קוד [IMG] פעיל
קוד HTML כבוי
מעבר לפורום



כל הזמנים המוצגים בדף זה הם לפי איזור זמן GMT +2. השעה כעת היא 16:31

הדף נוצר ב 0.12 שניות עם 10 שאילתות

הפורום מבוסס על vBulletin, גירסא 3.0.6
כל הזכויות לתוכנת הפורומים שמורות © 2024 - 2000 לחברת Jelsoft Enterprises.
כל הזכויות שמורות ל Fresh.co.il ©

צור קשר | תקנון האתר