Hallo
kann mir bitte jemand sagen warum dieser code 3 mal hintereinander ausgeführt wird und wie ich das verhindern kann ?
kann mir bitte jemand sagen warum dieser code 3 mal hintereinander ausgeführt wird und wie ich das verhindern kann ?
Java:
package sudoku;
import java.awt.BasicStroke;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.TextField;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.WindowConstants;
public class game {
JFrame fsudoku = new JFrame();
public game()
{
// button b = new button();
paint p = new paint();
fsudoku.setLayout(new BorderLayout());
// fsudoku.add(b, BorderLayout.SOUTH);
fsudoku.add(p, BorderLayout.CENTER);
fsudoku.setSize(410,460);
fsudoku.setLocation(200,200);
fsudoku.setVisible(true);
fsudoku.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
}
public static void main(String[] args){
new game();
}
}
Java:
package sudoku;
import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import javax.print.DocFlavor.STRING;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.JTextField;
public class paint extends JPanel {
public void paintComponent(Graphics g) {
this.setLayout(null);
// SPIELFELD---------------------------------------------------------------------------------------------------------
Graphics2D g2 = (Graphics2D) g;
g2.setStroke(new BasicStroke(3));
g2.setColor(Color.black);
// breite länge
g2.drawRect(15, 15, 360, 360);
//vertical
g2.drawLine(135, 15, 135, 375);
g2.drawLine(255, 15, 255, 375);
//horizontal
g2.drawLine(15, 135, 375, 135);
g2.drawLine(15, 255, 375, 255);
g2.setStroke(new BasicStroke(1));
int line = 55;
for ( int i = 1; i < 9; i++)
{
//vertical
g2.drawLine(line, 15, line, 375);
//horizontal
g2.drawLine(15, line, 375, line);
line = line + 40;
};
System.out.println("test");