Page 18 of 34 FirstFirst ... 81516171819202128 ... LastLast
Results 171 to 180 of 335
  1. #171

    Default Re: Java Programming


    nice ang netbeans nagpractice pa ko.

  2. #172

    Default Re: Java Programming

    asa ta ka download ug API?

  3. #173

    Default Re: Java Programming

    Unsa nga version? 1.5?

    J2SE 5.0 API Download <-- edit nako ang title. :mrgreen:

  4. #174

    Default Re: Java Programming

    Quote Originally Posted by apart
    asa ta ka download ug API?
    API? or API Documentation? if the latter, the post above this one is the anwer...if the former, its already included with the jdk you are using..the standard api, at least..

  5. #175

    Default Re: Java Programming

    guys, naa lang jud unta koy i konsulta, regarding ani akong program!!
    koan ni siya, tictactoe game ni nga program! but, ang akong problema kay dli mag cge nalng ug balik ang x turn ani!!
    can u help me solve this problem!?

    morag sa kanang gi bold nako nga code man ang sayop! galibog jud ko unsaon nako pag compare between x and y nga turns..!!

    tanx...!


    import javax.swing.*;
    import java.awt.*;
    import java.awt.event.*;

    public class Jerus extends JFrame implements MouseListener,ActionListener{

    public static final int height = 250;
    public static final int width = 250;
    int numClicks;
    boolean isDone = false;
    boolean xTurn = true;
    JLabel status = new JLabel("Welcome to my Game.!");
    JLabel&#91;]&#91;] grid = new JLabel[3][3];
    char&#91;]&#91;] game = new char[3][3];
    JButton restart = new JButton("restart");

    public Jerus(){
    JPanel top;
    JPanel bottom;
    JPanel center;

    setSize(width,height);
    setTitle("Jerus' Project");
    addWindowListener(new WindowTerminator());
    Container contentPane = getContentPane();
    contentPane.setLayout(new BorderLayout());

    top = new JPanel();
    top.setLayout(new FlowLayout());
    top.add(status);


    center = new JPanel();
    center.setLayout(new GridLayout(3,3,3,3));
    center.setBackground(Color.BLACK);

    for(int row=0; row<3; row++){
    for(int col=0; col<3; col++){
    grid[row][col] = new JLabel(" ",JLabel.CENTER);
    grid[row][col].addMouseListener(this);
    grid[row][col].setBackground(Color.WHITE);

    center.add(grid[row][col]);
    game[row][col] = ' ';

    }
    }

    bottom = new JPanel();
    bottom.setLayout(new FlowLayout());
    bottom.add(restart);



    contentPane.add(top,BorderLayout.NORTH);
    contentPane.add(center,BorderLayout.CENTER);
    contentPane.add(bottom,BorderLayout.SOUTH);


    }

    public void mouseClicked(MouseEvent e){
    if(isDone){
    resetGame();
    }
    JLabel clicked = (JLabel)e.getSource();
    next:
    for(int i=0; i<3; i++){

    for(int j=0; j<3; j++ ){

    if(clicked == grid[i][j]){

    if(clicked != grid[i][j]){
    status.setText("Invalid Move");
    break next;
    }

    if((clicked == grid[i][j]) && (xTurn==false)){
    clicked.setText("x");
    clicked.setForeground(Color.RED);
    game[i][j] = 'x';

    }
    else{
    clicked.setText("o");
    clicked.setForeground(Color.BLUE);
    game[i][j] = 'o';
    }
    xTurn = true;
    numClicks++;
    gameOver();
    }// end of if.

    }//end of inner loop

    }//end of outer loop


    }//end of mouseClicked

    public void resetGame(){


    for(int i=0; i<3; i++){
    for(int j=0; j<3; j++){
    grid[i][j] = new JLabel(" ");
    game[i][j] = ' ';

    }
    }
    numClicks = 0;
    xTurn = true;
    }

    public void gameOver(){

    char winner = ' ';

    if((game[0][0] == game[1][1]) && (game[1][1] == game[2][2])){
    winner = game[0][0];}
    else if((game[2][0] == game[1][1]) && (game[2][0] == game[0][2])){
    winner = game[2][0];}
    else{

    for(int i=0; i<3; i++){
    if((game[i][0] != ' ') && (game[i][0] == game[i][1]) && game[i][1] == game[i][2]){
    winner = game[i][0];
    }
    else if((game[0][i] != ' ') && (game[0][i] == game[1][i]) && (game[1][i] == game[2][i])){
    winner = game[0][1];
    }
    }
    }
    isDone = true;
    if(winner == ' ' && numClicks == 9){
    status.setText("Tie Game!!");
    }
    else if(winner != ' '){
    status.setText("Game Over "+ winner +" Won!!");
    }
    else
    status.setText((xTurn ? "X's Turn" : "O's Turn"));
    isDone = false;
    }

    public void actionPerformed(ActionEvent ex){
    resetGame();
    }

    public static void main(String&#91;] args){
    Jerus r = new Jerus();
    r.setVisible(true);
    }

    public void mouseEntered(MouseEvent e){ }
    public void mousePressed(MouseEvent e){ }
    public void mouseExited(MouseEvent e){ }
    public void mouseReleased(MouseEvent e){ }
    public void mouseMoved(MouseEvent e){ }
    public void mouseDragged(MouseEvent e){ }
    }


  6. #176

    Default Re: Java Programming

    if(clicked == grid[j]){

    if(clicked != grid[j]){
    status.setText("Invalid Move");
    break next;
    }

    if((clicked == grid[j]) && (xTurn==false)){
    clicked.setText("x");
    clicked.setForeground(Color.RED);
    game[j] = 'x';

    }
    else{
    clicked.setText("o");
    clicked.setForeground(Color.BLUE);
    game[j] = 'o';
    }
    xTurn = true;
    numClicks++;
    gameOver();
    }// end of if.
    your if(clicked != grid[j]) statement is not necessary. it wont pass through that because click == grid[j] always.

    what's the use of the variable i?

  7. #177

    Default Re: Java Programming

    @jerx bay gamiti daw ug code tags imong code.. i dont think mo compile sad ni ug tarong nga code kay you are comparing a JLabel to an array of JLabels.. if(clicked != grid[j]).. anyways, try daw gamit ug code tags..

  8. #178

    Default Re: Java Programming

    @jerx: TIC TAC TOE ba ni nga game? Dili man cguro kailangan ang if(clicked == grid[j]).

    If mouse_clicked gani ang label then assign dayon og value sa label 'X' ba or 'O'. Then check dayon ang matrix if naay na ba'y naka-form og straight 'X' or 'O'. If naay na'y naka-form report dayon kung kinsa ang player nga winner. Maka-ila ra man ka kung kinsa ang ni-daog ka'y each symbol 'X' or 'O' is assigned to each player man.

    BTW parehas mo og pattern sa code ni sweetz (usa nga mga friend nako nga istoryan diri).

  9. #179

    Default Re: Java Programming

    dili sad jud pwede ang clicked == grid[j] bay kay mag error na kay nag compare man na ug array nga object ug dili array nga object..incomparable data types..

  10. #180

    Default Re: Java Programming

    Quote Originally Posted by boxingfan529
    what's the use of the variable i?
    Ang i og j ka'y indices sa iyang matrix which is grid.

  11.    Advertisement

Page 18 of 34 FirstFirst ... 81516171819202128 ... LastLast

Similar Threads

 
  1. JAVA PROGRAMMING *****
    By bardnekom in forum Programming
    Replies: 20
    Last Post: 04-18-2013, 12:51 PM
  2. MOVED: JAVA PROGRAMMING *****
    By vern in forum Software & Games (Old)
    Replies: 0
    Last Post: 03-23-2008, 02:43 AM
  3. Java programming help pls...
    By mr_gwen in forum Programming
    Replies: 6
    Last Post: 11-03-2006, 12:30 AM
  4. nid help..java programming
    By ronninalpha in forum Programming
    Replies: 3
    Last Post: 09-13-2006, 07:55 PM
  5. MOVED: Java Programming
    By BadDudes in forum Software & Games (Old)
    Replies: 0
    Last Post: 04-28-2006, 12:04 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
about us
We are the first Cebu Online Media.

iSTORYA.NET is Cebu's Biggest, Southern Philippines' Most Active, and the Philippines' Strongest Online Community!
follow us
#top