Warum muss es immer so scheiße spät werden, wenn man vorm PC sitzt??
ich verstehs nicht -.-
stolenhentai.tk
link ^^
import java.awt.event.*;
import java.awt.*;import javax.swing.*;
/*
* Created on 29.11.2004
*
* TODO To change the template for this generated file go to
* Window – Preferences – Java – Code Style – Code Templates
*//**
* @author Oluf Lorenzen
*
* TODO To change the template for this generated type comment go to
* Window – Preferences – Java – Code Style – Code Templates
*/public class TickTackToe extends JFrame implements ActionListener {
Spielfeld sf;
boolean user1;public TickTackToe() {
super();addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
dispose();
System.exit(0);
}
});Initialisieren();
}
private void Initialisieren() {
/**
* Definition des Contents.
*/
Container content = this.getContentPane();
JButton start = new JButton(”Neues Spiel”);
JButton beenden = new JButton(”Beenden”);
sf = new Spielfeld();
/**
* Einfügen des Contents.
*/
content.add(start, BorderLayout.NORTH);
start.addActionListener (this);
content.add(beenden, BorderLayout.AFTER_LAST_LINE);
beenden.addActionListener (this);
content.add(sf, BorderLayout.CENTER);
user1=true;}
public void actionPerformed(ActionEvent e) {
if (e.getActionCommand() == “Beenden”) {
dispose();
System.exit(0);
}else {
if (e.getActionCommand() == “Neues Spiel”) {
sf.Initialisieren();}
}
}public static void main(String[] args) {
TickTackToe frame = new TickTackToe();
frame.setSize(800, 600);
frame.setTitle(”TickTackToe”);
frame.setVisible(true);
}private class Spielfeld extends JPanel {
Spielzelle sp[][];
public Spielfeld() {
super();
sp = new Spielzelle[3][3];
Button[][] button = new Button[3][3];
this.setLayout(new GridLayout(3,3,5,5));/* add(new Button(”1″));
add(new Button(”2″));
add(new Button(”3″));
add(new Button(”4″));
add(new Button(”5″));
add(new Button(”6″));
add(new Button(”7″));
add(new Button(”8″));
add(new Button(”9″));*/
for (int reihe=0; reihe<3; reihe++) {
for (int spalte=0; spalte<3; spalte++) {
sp[reihe][spalte] = new Spielzelle(”#”);
add (sp [reihe][spalte]);
}
}
}
public void Initialisieren () {
for (int reihe=0; reihe<3; reihe++) {
for (int spalte=0; spalte<3; spalte++) {
sp[reihe][spalte].setText(”~~”);
}
}
}
}}
2te datei ^^
import java.awt.Color;
import java.awt.event.*;
import javax.swing.*;/*
* Created on 13.12.2004
*
* TODO To change the template for this generated file go to
* Window – Preferences – Java – Code Style – Code Templates
*//**
* @author Oluf Lorenzen
*
* TODO To change the template for this generated type comment go to
* Window – Preferences – Java – Code Style – Code Templates
*/public class Spielzelle extends JLabel implements MouseListener {
private Color farbe;
boolean user1;public Spielzelle(String _s) {
super(_s, CENTER);
this.addMouseListener(this);
setOpaque(true);
Color farbe;}
/* (non-Javadoc)
* @see java.awt.event.MouseListener#mouseClicked(java.awt.event.MouseEvent)
*/
public void mouseClicked(MouseEvent e) {
// TODO Auto-generated method stub
//setText(”blub___s”);
//for (int user=0; user<1; user++) {//}
if (getText()==”#”) {
if (user1 == true) {
setText(”X”);
user1=false;}
else {
setText(”O”);
user1=true;}
}}
/* (non-Javadoc)
* @see java.awt.event.MouseListener#mouseEntered(java.awt.event.MouseEvent)
*/
public void mouseEntered(MouseEvent e) {
// TODO Auto-generated method stub
farbe = getBackground();
setBackground(Color.WHITE);
}/* (non-Javadoc)
* @see java.awt.event.MouseListener#mouseExited(java.awt.event.MouseEvent)
*/
public void mouseExited(MouseEvent e) {
// TODO Auto-generated method stub
//farbe = getBackground();
setBackground(farbe);
//setBackground(Color.OPAQUE);
}/* (non-Javadoc)
* @see java.awt.event.MouseListener#mousePressed(java.awt.event.MouseEvent)
*/
public void mousePressed(MouseEvent e) {
// TODO Auto-generated method stub}
/* (non-Javadoc)
* @see java.awt.event.MouseListener#mouseReleased(java.awt.event.MouseEvent)
*/
public void mouseReleased(MouseEvent e) {
// TODO Auto-generated method stub
/*farbe = getBackground();
setBackground(Color.GREEN);*/
}for () {
}
}