我无法引用 class - 某个地方的问题
I cannot reference a class - issues somewhere
由于我对 Java 还很陌生,所以我只知道创建变量、导入内容和其他一些内容;但我不明白的是为什么 begin() 函数不是 运行 并且任何可以解释发生了什么并可能以更好的方式重写它的帮助将不胜感激!
谢谢,
杰瑞
package nEW;
// Not Working - trying to format start by making a new "begin" object when run.
import java.awt.Color;
import java.awt.Component;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.RenderingHints;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import javax.swing.JFrame;
import javax.swing.Renderer;
import javax.swing.Timer;
import javax.print.*;
public class Chessstart
{
public static void main(String[] args) {
open.start();
}
static class open
{
// All packages imported , ready for use... Add more if need be : +
public class begin implements ActionListener, KeyListener
{
public boolean board_show =true;
public int AOB1 = 16;
public int AOB2 = 16;
public static final int WOB = 640;
public static final int HOB = 640;
public int GStat = 0;
// Defines when game is playing, toggle-able twice 0, 1, 2
// 0 = Menu, 1 = Paused, 2 = Game
// Might Become Redundant
// TODO Make this feature redundant!
public boolean click, space;
public int turn;
public Component renderer;
public void ScreenUp()
{
Timer timer = new Timer(20, this);
JFrame jframe = new JFrame("CHESS");
jframe.setSize(WOB, HOB);
jframe.setVisible(true);
jframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jframe.add(renderer);
jframe.addKeyListener(this);
timer.start();
}
public void render(Graphics g)
{
g.setColor(Color.black);
g.fillRect(0, 0, WOB, HOB);
if (GStat == 0 || GStat == 1 || GStat == 2)
{
if (GStat == 0)
{
System.out.print("GStat return 0 - Render running");
}
if (GStat == 1)
{
System.out.print("GStat return 1 - render running");
}
if (GStat == 2)
{
System.out.print("GStat return 2 - render running");
}
}
}
@Override
public void actionPerformed(ActionEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void keyPressed(KeyEvent arg0){
// TODO Auto-generated method stub
}
@Override
public void keyReleased(KeyEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void keyTyped(KeyEvent arg0) {
// TODO Auto-generated method stub
}
}
public static void start() {
open.begin();
}
}
}
关于 Java 中的接口,我也是相当新的,但是...
就像 Ousmane Mahy Diaw 在他的评论中提到的那样,begin 是一个 class,而不是一个函数。这是基本的 Java 知识,所以首先我建议您练习使用命令行下棋。接口应该是一项单独的工作。
那个代码有很多问题。我推荐使用 Netbeans IDE。它可以帮助您解决基本错误。
我建议在使用 JFrames 构建接口时这样做:
import java.awt.Color;
import java.awt.Component;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.RenderingHints;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import javax.swing.JFrame;
import javax.swing.Renderer;
import javax.swing.Timer;
import javax.print.*;
public class Chessstart extends JFrame implements ActionListener, KeyListener
{
public boolean board_show =true;
public int AOB1 = 16;
public int AOB2 = 16;
public static final int WOB = 640;
public static final int HOB = 640;
public int GStat = 0;
// Defines when game is playing, toggle-able twice 0, 1, 2
// 0 = Menu, 1 = Paused, 2 = Game
// Might Become Redundant
// TODO Make this feature redundant!
public boolean click, space;
public int turn;
public Component renderer;
public static void main(String[] args) {
Chessstart ch = new Chessstart();
//ch.render(ch.getGraphics());
ch.screenUp();
}
public void screenUp()
{
Timer timer = new Timer(20, this);
JFrame jframe = new JFrame("CHESS");
jframe.setSize(WOB, HOB);
jframe.setVisible(true);
jframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jframe.add(renderer);
jframe.addKeyListener(this);
timer.start();
}
public void render(Graphics g)
{
g.setColor(Color.black);
g.fillRect(0, 0, WOB, HOB);
if (GStat == 0 || GStat == 1 || GStat == 2)
{
if (GStat == 0)
{
System.out.print("GStat return 0 - Render running");
}
if (GStat == 1)
{
System.out.print("GStat return 1 - render running");
}
if (GStat == 2)
{
System.out.print("GStat return 2 - render running");
}
}
}
@Override
public void actionPerformed(ActionEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void keyPressed(KeyEvent arg0){
// TODO Auto-generated method stub
}
@Override
public void keyReleased(KeyEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void keyTyped(KeyEvent arg0) {
// TODO Auto-generated method stub
}
}
这至少会打开您的 window,但请注意,您需要先初始化一个对象,然后再使用它。这意味着如果没有初始化图形,渲染将不会成功。
另外,为什么还要使用渲染器?你不需要,windows 出现并且没有像这样的错误:
import java.awt.Color;
import java.awt.Component;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.RenderingHints;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import javax.swing.JFrame;
import javax.swing.Renderer;
import javax.swing.Timer;
import javax.print.*;
public class Chessstart extends JFrame implements ActionListener, KeyListener
{
public boolean board_show =true;
public int AOB1 = 16;
public int AOB2 = 16;
public static final int WOB = 640;
public static final int HOB = 640;
public int GStat = 0;
// Defines when game is playing, toggle-able twice 0, 1, 2
// 0 = Menu, 1 = Paused, 2 = Game
// Might Become Redundant
// TODO Make this feature redundant!
public boolean click, space;
public int turn;
public Component renderer;
public static void main(String[] args) {
Chessstart ch = new Chessstart();
//ch.render(ch.getGraphics());
ch.screenUp();
}
public void screenUp()
{
Timer timer = new Timer(20, this);
JFrame jframe = new JFrame("CHESS");
jframe.setSize(WOB, HOB);
jframe.setVisible(true);
jframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jframe.addKeyListener(this);
timer.start();
}
public void render(Graphics g)
{
g.setColor(Color.black);
g.fillRect(0, 0, WOB, HOB);
if (GStat == 0 || GStat == 1 || GStat == 2)
{
if (GStat == 0)
{
System.out.print("GStat return 0 - Render running");
}
if (GStat == 1)
{
System.out.print("GStat return 1 - render running");
}
if (GStat == 2)
{
System.out.print("GStat return 2 - render running");
}
}
}
@Override
public void actionPerformed(ActionEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void keyPressed(KeyEvent arg0){
// TODO Auto-generated method stub
}
@Override
public void keyReleased(KeyEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void keyTyped(KeyEvent arg0) {
// TODO Auto-generated method stub
}
}
由于我对 Java 还很陌生,所以我只知道创建变量、导入内容和其他一些内容;但我不明白的是为什么 begin() 函数不是 运行 并且任何可以解释发生了什么并可能以更好的方式重写它的帮助将不胜感激!
谢谢, 杰瑞
package nEW;
// Not Working - trying to format start by making a new "begin" object when run.
import java.awt.Color;
import java.awt.Component;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.RenderingHints;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import javax.swing.JFrame;
import javax.swing.Renderer;
import javax.swing.Timer;
import javax.print.*;
public class Chessstart
{
public static void main(String[] args) {
open.start();
}
static class open
{
// All packages imported , ready for use... Add more if need be : +
public class begin implements ActionListener, KeyListener
{
public boolean board_show =true;
public int AOB1 = 16;
public int AOB2 = 16;
public static final int WOB = 640;
public static final int HOB = 640;
public int GStat = 0;
// Defines when game is playing, toggle-able twice 0, 1, 2
// 0 = Menu, 1 = Paused, 2 = Game
// Might Become Redundant
// TODO Make this feature redundant!
public boolean click, space;
public int turn;
public Component renderer;
public void ScreenUp()
{
Timer timer = new Timer(20, this);
JFrame jframe = new JFrame("CHESS");
jframe.setSize(WOB, HOB);
jframe.setVisible(true);
jframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jframe.add(renderer);
jframe.addKeyListener(this);
timer.start();
}
public void render(Graphics g)
{
g.setColor(Color.black);
g.fillRect(0, 0, WOB, HOB);
if (GStat == 0 || GStat == 1 || GStat == 2)
{
if (GStat == 0)
{
System.out.print("GStat return 0 - Render running");
}
if (GStat == 1)
{
System.out.print("GStat return 1 - render running");
}
if (GStat == 2)
{
System.out.print("GStat return 2 - render running");
}
}
}
@Override
public void actionPerformed(ActionEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void keyPressed(KeyEvent arg0){
// TODO Auto-generated method stub
}
@Override
public void keyReleased(KeyEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void keyTyped(KeyEvent arg0) {
// TODO Auto-generated method stub
}
}
public static void start() {
open.begin();
}
}
}
关于 Java 中的接口,我也是相当新的,但是...
就像 Ousmane Mahy Diaw 在他的评论中提到的那样,begin 是一个 class,而不是一个函数。这是基本的 Java 知识,所以首先我建议您练习使用命令行下棋。接口应该是一项单独的工作。
那个代码有很多问题。我推荐使用 Netbeans IDE。它可以帮助您解决基本错误。
我建议在使用 JFrames 构建接口时这样做:
import java.awt.Color;
import java.awt.Component;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.RenderingHints;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import javax.swing.JFrame;
import javax.swing.Renderer;
import javax.swing.Timer;
import javax.print.*;
public class Chessstart extends JFrame implements ActionListener, KeyListener
{
public boolean board_show =true;
public int AOB1 = 16;
public int AOB2 = 16;
public static final int WOB = 640;
public static final int HOB = 640;
public int GStat = 0;
// Defines when game is playing, toggle-able twice 0, 1, 2
// 0 = Menu, 1 = Paused, 2 = Game
// Might Become Redundant
// TODO Make this feature redundant!
public boolean click, space;
public int turn;
public Component renderer;
public static void main(String[] args) {
Chessstart ch = new Chessstart();
//ch.render(ch.getGraphics());
ch.screenUp();
}
public void screenUp()
{
Timer timer = new Timer(20, this);
JFrame jframe = new JFrame("CHESS");
jframe.setSize(WOB, HOB);
jframe.setVisible(true);
jframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jframe.add(renderer);
jframe.addKeyListener(this);
timer.start();
}
public void render(Graphics g)
{
g.setColor(Color.black);
g.fillRect(0, 0, WOB, HOB);
if (GStat == 0 || GStat == 1 || GStat == 2)
{
if (GStat == 0)
{
System.out.print("GStat return 0 - Render running");
}
if (GStat == 1)
{
System.out.print("GStat return 1 - render running");
}
if (GStat == 2)
{
System.out.print("GStat return 2 - render running");
}
}
}
@Override
public void actionPerformed(ActionEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void keyPressed(KeyEvent arg0){
// TODO Auto-generated method stub
}
@Override
public void keyReleased(KeyEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void keyTyped(KeyEvent arg0) {
// TODO Auto-generated method stub
}
}
这至少会打开您的 window,但请注意,您需要先初始化一个对象,然后再使用它。这意味着如果没有初始化图形,渲染将不会成功。
另外,为什么还要使用渲染器?你不需要,windows 出现并且没有像这样的错误:
import java.awt.Color;
import java.awt.Component;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.RenderingHints;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import javax.swing.JFrame;
import javax.swing.Renderer;
import javax.swing.Timer;
import javax.print.*;
public class Chessstart extends JFrame implements ActionListener, KeyListener
{
public boolean board_show =true;
public int AOB1 = 16;
public int AOB2 = 16;
public static final int WOB = 640;
public static final int HOB = 640;
public int GStat = 0;
// Defines when game is playing, toggle-able twice 0, 1, 2
// 0 = Menu, 1 = Paused, 2 = Game
// Might Become Redundant
// TODO Make this feature redundant!
public boolean click, space;
public int turn;
public Component renderer;
public static void main(String[] args) {
Chessstart ch = new Chessstart();
//ch.render(ch.getGraphics());
ch.screenUp();
}
public void screenUp()
{
Timer timer = new Timer(20, this);
JFrame jframe = new JFrame("CHESS");
jframe.setSize(WOB, HOB);
jframe.setVisible(true);
jframe.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jframe.addKeyListener(this);
timer.start();
}
public void render(Graphics g)
{
g.setColor(Color.black);
g.fillRect(0, 0, WOB, HOB);
if (GStat == 0 || GStat == 1 || GStat == 2)
{
if (GStat == 0)
{
System.out.print("GStat return 0 - Render running");
}
if (GStat == 1)
{
System.out.print("GStat return 1 - render running");
}
if (GStat == 2)
{
System.out.print("GStat return 2 - render running");
}
}
}
@Override
public void actionPerformed(ActionEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void keyPressed(KeyEvent arg0){
// TODO Auto-generated method stub
}
@Override
public void keyReleased(KeyEvent arg0) {
// TODO Auto-generated method stub
}
@Override
public void keyTyped(KeyEvent arg0) {
// TODO Auto-generated method stub
}
}