السلام عليكم
انا بعت موضوع امبارح اظن انو ادارة المنتدى شافته انا ما قصدتش انى اخالف القوانين بس انا ليا سنة كاملة بدور على حد يساعدنى فبعت اسأل اذا فيه حد عنده امكانية للمساعدة عموما شكرا على اغلاق الموضوع انا بكرر طلبي هنا بس بالطريقة التى تقبلها الإدارة حعرض الكود والمشكلة
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package connect4;
public class Disc
{
private int player ;
private boolean isEmpty =true;
String st_p1 = "/icon/p1.gif";
String st_p2 = "/icon/p2.gif";
String st_org = "/icon/orginal.gif";
public Disc()
{
}
public void set_Player(int val)
{
if (isEmpty)
{
player = val;
isEmpty = false;
if (val == 1)
{
isEmpty =false;
} else
{
}
}
else
{
return;
}
}
public int get_Player()
{
return player;
}
public String get_Label()
{
if (player == 1)
{
return st_p1;
}
else if (player == 2)
{
return st_p2;
}
else
{
return st_org;
}
}
public boolean Is_Empty()
{
return isEmpty;
}
}
_______________________________________________
* gui.java
*
* Created on June 29, 2008, 12:56 AM
*/
package connect4;
import javax.swing.JOptionPane;
import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.MouseEvent;
import javax.swing.GroupLayout;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
/**
*
* @author root
*/
public class gui extends javax.swing.JPanel {
private int turn_Who = 1;
private JLabel[][] JLP_Disck = new JLabel[6][7];
private Disc[][] d = new Disc[6][7];
private JPanel Header, Body;
private JLabel Player_Flag = new JLabel("Player1", new ImageIcon(getClass().getResource("/icon/orginal.gif")), JLabel.LEFT);
/** Creates new form gui */
public gui() {
Header = new JPanel(new BorderLayout());
Body = new JPanel(new GridLayout(6, 7, 5, 5));
for (int k = 0; k < 6; k++) {
for (int l = 0; l < 7; l++) {
JLP_Disck[k][l] = new JLabel(new ImageIcon(getClass().getResource("/icon/orginal.gif")));
//JLP_Disck[k][l].setIcon(new ImageIcon(getClass().getResource("/icon/orginal.gif")));
System.out.println("Test");
Body.add(JLP_Disck[k][l]);
}
}
for (int i = 0; i < 6; i++) {
for (int j = 0; j < 7; j++) {
d[j] = new Disc();
}
}
initComponents();
setLayout(new BorderLayout());
Header.add(Player_Flag);
add(Header, BorderLayout.NORTH);
add(Body, BorderLayout.CENTER);
//--------------------Now Create Listeners
JLP_Disck[0][0].addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt)
{
jLP00MouseClicked(evt);
}
private void jLP00MouseClicked(MouseEvent evt) {
if (!d[0][0].Is_Empty()) {
JOptionPane.showMessageDialog(null, "the column is full"); //if the player click a pressed Disck we should not count it
} else {
int k = check_empty(0);
if (turn_Who == 1) {
turn_Who = 2;
d[k][0].set_Player(1);
Player_Flag.setIcon(new ImageIcon(getClass().getResource("/icon/p2.gif")));
JLP_Disck[k][0].setIcon(new ImageIcon(getClass().getResource("/icon/p1.gif")));
} else {
turn_Who = 1;
Player_Flag.setIcon(new ImageIcon(getClass().getResource("/icon/p1.gif")));
d[k][0].set_Player(2);
JLP_Disck[k][0].setIcon(new ImageIcon(getClass().getResource("/icon/p2.gif")));
}
}
}
});
//----------------------------------------------
JLP_Disck[0][1].addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
jLP01MouseClicked(evt);
}
private void jLP01MouseClicked(MouseEvent evt) {
if (!d[0][2].Is_Empty()) {
JOptionPane.showMessageDialog(null, "the column is full"); //if the player click a pressed Disck we should not count it
} else {
int k = check_empty(1);
if (turn_Who == 1) {
turn_Who = 2;
d[k][1].set_Player(1);
Player_Flag.setIcon(new ImageIcon(getClass().getResource("/icon/p2.gif")));
JLP_Disck[k][1].setIcon(new ImageIcon(getClass().getResource("/icon/p1.gif")));
} else {
turn_Who = 1;
Player_Flag.setIcon(new ImageIcon(getClass().getResource("/icon/p1.gif")));
d[k][1].set_Player(2);
JLP_Disck[k][1].setIcon(new ImageIcon(getClass().getResource("/icon/p2.gif")));
}
}
}
});
//-----------------------------------------
JLP_Disck[0][2].addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
jLP02MouseClicked(evt);
}
private void jLP02MouseClicked(MouseEvent evt) {
if (!d[0][2].Is_Empty()) {
JOptionPane.showMessageDialog(null, "the column is full"); //if the player click a pressed Disck we should not count it
} else {
int k = check_empty(2);
if (turn_Who == 1) {
turn_Who = 2;
d[k][2].set_Player(1);
Player_Flag.setIcon(new ImageIcon(getClass().getResource("/icon/p2.gif")));
JLP_Disck[k][2].setIcon(new ImageIcon(getClass().getResource("/icon/p1.gif")));
} else {
turn_Who = 1;
Player_Flag.setIcon(new ImageIcon(getClass().getResource("/icon/p1.gif")));
d[k][2].set_Player(2);
JLP_Disck[k][2].setIcon(new ImageIcon(getClass().getResource("/icon/p2.gif")));
}
}
}
});
//----------------------------------------------
JLP_Disck[0][3].addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
jLP03MouseClicked(evt);
}
private void jLP03MouseClicked(MouseEvent evt) {
if (!d[0][3].Is_Empty()) {
JOptionPane.showMessageDialog(null, "the column is full"); //if the player click a pressed Disck we should not count it
} else {
int k = check_empty(3);
if (turn_Who == 1) {
turn_Who = 2;
d[k][3].set_Player(1);
Player_Flag.setIcon(new ImageIcon(getClass().getResource("/icon/p2.gif")));
JLP_Disck[k][3].setIcon(new ImageIcon(getClass().getResource("/icon/p1.gif")));
} else {
turn_Who = 1;
Player_Flag.setIcon(new ImageIcon(getClass().getResource("/icon/p1.gif")));
d[k][3].set_Player(2);
JLP_Disck[k][3].setIcon(new ImageIcon(getClass().getResource("/icon/p2.gif")));
}
}
}
});
//------------------------------------------------
JLP_Disck[0][4].addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
jLP04MouseClicked(evt);
}
private void jLP04MouseClicked(MouseEvent evt) {
if (!d[0][4].Is_Empty()) {
JOptionPane.showMessageDialog(null, "the column is full"); //if the player click a pressed Disck we should not count it
} else {
int k = check_empty(4);
if (turn_Who == 1) {
turn_Who = 2;
d[k][4].set_Player(1);
Player_Flag.setIcon(new ImageIcon(getClass().getResource("/icon/p2.gif")));
JLP_Disck[k][4].setIcon(new ImageIcon(getClass().getResource("/icon/p1.gif")));
} else {
turn_Who = 1;
Player_Flag.setIcon(new ImageIcon(getClass().getResource("/icon/p1.gif")));
d[k][4].set_Player(2);
JLP_Disck[k][4].setIcon(new ImageIcon(getClass().getResource("/icon/p2.gif")));
}
}
}
});
//--------------------------------------------------
JLP_Disck[0][5].addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
jLP05MouseClicked(evt);
}
private void jLP05MouseClicked(MouseEvent evt) {
if (!d[0][5].Is_Empty()) {
JOptionPane.showMessageDialog(null, "the column is full"); //if the player click a pressed Disck we should not count it
} else {
int k = check_empty(5);
if (turn_Who == 1) {
turn_Who = 2;
d[k][5].set_Player(1);
Player_Flag.setIcon(new ImageIcon(getClass().getResource("/icon/p2.gif")));
JLP_Disck[k][5].setIcon(new ImageIcon(getClass().getResource("/icon/p1.gif")));
} else {
turn_Who = 1;
Player_Flag.setIcon(new ImageIcon(getClass().getResource("/icon/p1.gif")));
d[k][5].set_Player(2);
JLP_Disck[k][5].setIcon(new ImageIcon(getClass().getResource("/icon/p2.gif")));
}
}
}
});
//--------------------------------------------------
JLP_Disck[0][6].addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
jLP05MouseClicked(evt);
}
private void jLP05MouseClicked(MouseEvent evt) {
if (!d[0][6].Is_Empty()) {
JOptionPane.showMessageDialog(null, "the column is full"); //if the player click a pressed Disck we should not count it
} else {
int k = check_empty(6);
if (turn_Who == 1) {
turn_Who = 2;
d[k][6].set_Player(1);
Player_Flag.setIcon(new ImageIcon(getClass().getResource("/icon/p2.gif")));
JLP_Disck[k][6].setIcon(new ImageIcon(getClass().getResource("/icon/p1.gif")));
} else {
turn_Who = 1;
Player_Flag.setIcon(new ImageIcon(getClass().getResource("/icon/p1.gif")));
d[k][6].set_Player(2);
JLP_Disck[k][6].setIcon(new ImageIcon(getClass().getResource("/icon/p2.gif")));
}
}
}
});
//---------------------------------------------------
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
this.setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 370, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 282, Short.MAX_VALUE)
);
}// </editor-fold>//GEN-END:initComponents
// Variables declaration - do not modify//GEN-BEGIN:variables
// End of variables declaration//GEN-END:variables
private int check_empty(int i) {
for (int n = 5; n >= 0; n--) {
if (d[n].Is_Empty()) {
return n;
}
}
return 10; // return any number as a sign to failure
}
}
___________________________________________________________
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package connect4;
import javax.swing.JFrame;
/**
*
* @author XPPRESP3
*/
public class Main extends JFrame{
public Main() {
super("Connect 4");
pack();
add(new gui());
setVisible(true);
setSize(400, 400);
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
Main m = new Main();
m.setVisible(true);
m.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
__________________________________________________
اول مشكلة فلكود عندى هيا انو لما اجيت اعيد برمجة الكود وكتبت
package connect4;
جابلي error انا مش عارفة هوا ايه الباكيج ده وفين تعريفه
المشكلة التانية انو في الكلاس التانى كل التعريفات بيديني فيها error لأنه مش مكتوب ليها type
ملاحظة : المشروع ده لما اشغله بيتطبق عادى وبيديني ال bourd لكن لما احط الكود في project تانى بيحصل ال error
دول أول مشكلتين عندى