我是Java的新手,我正在尝试制作乒乓球游戏。我试图从main引用一个类文件(该类文件与main不在同一文件内)以保持主文件的整洁。在Java中这可能吗?下面是我要感谢的代码。
Pong.java(主类)
package pong;
public class Pong {
public static void main(String[] args){
// Pull Frame Class from Frame.java to draw rectangle
}
}
Frame.java(绘制JFrame)
package pong;
import java.awt.Graphics;
import javax.swing.JFrame;
import javax.swing.JPanel;
import java.awt.Color;
public class Frame extends JPanel {
public void BoundingBox(Graphics g){
System.out.print("Java Pong From Frame!!!");
JFrame frame = new JFrame("Welcome to Java Pong");
frame.setVisible(true);
frame.setSize(800,600);
frame.setResizable(false);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
//Areana border
g.setColor(Color.blue);
g.fillRect(10,10,773,550);
}
}