현재 작은 코딩 프로젝트에서 작업 중이며 문제가 있습니다. 나는 과거의 일을 살펴 봤는데 왜이 프로그램이 페인트 법을 부르지 않는지 알아낼 수 없다. 현재 프레임에 원을 그리려하고 있습니다.객체 클래스가 화면에 페인팅하지 않습니다.
다음은 그리려는 간단한 원에 대한 창과 개체 클래스를 만듭니다.
public class Main {
public static void main(String[] args) {
final int WIDTH = 700, HEIGHT = 900;
JFrame frame = new JFrame("Physics Demo");
JPanel content = new JPanel();
content.setLayout(new GridLayout(1, 0, 0, 0));
Character ball = new Character(WIDTH, HEIGHT);
Timer changeFrame = new Timer (100, ball);
frameSetup(frame, content, WIDTH, HEIGHT, ball, changeFrame);
}
public static void frameSetup(JFrame frame, JPanel content, int WIDTH, int HEIGHT, Character ball, Timer changeFrame){
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setContentPane(content);
content.add(ball);
frame.addKeyListener(ball);
frame.setPreferredSize(new Dimension(WIDTH, HEIGHT));
frame.setResizable(false);
frame.pack();
frame.setLocationRelativeTo(null);
frame.setVisible(true);
changeFrame.start();
}
}
아래의 클래스는 내가 프로그램을 실행할 때 콘솔에서 응답을, 객체 클래스입니다. 캐릭터는 한 번 (한 번씩) 트리거하고 actionPreformed 메소드는 타이머와 함께 루프에서 실행됩니다. 어떤 이유로 페인트 클래스를 실행하지 않습니다.
public class Character extends JPanel implements ActionListener, KeyListener{
/* Identify the Objects values and physics,
* Characters weight, size and properties are below.
*
*/
private static final long serialVersionUID = 1L;
final int characterRadius = 30;
final double characterWeight = 0.5;
int characterY, characterX;
boolean bouncy;
public Character(int WIDTH, int HEIGHT){
System.out.println("Character called upon... " + WIDTH);
}
public void characterObject(Graphics g, int WIDTH, int HEIGHT){
super.paint(g);
System.out.println("characterObject graphics called upon... " + WIDTH);
g.setColor(Color.BLUE);
g.fillOval(350, 450, characterRadius, characterRadius);
}
/*
* Ball does not have any player interactions
*/
@Override
public void keyPressed(KeyEvent buttonPressed) {
}
@Override
public void keyReleased(KeyEvent arg0) {
}
@Override
public void keyTyped(KeyEvent arg0) {
}
//******************************************
@Override
public void actionPerformed(ActionEvent arg0) {
System.out.println("actionPreformed called upon...");
repaint();
}
}
는 지금 잠시 동안 시행 착오를하고있다 그리고 나는 내가 최후의 수단으로이 사용하고 그것을 알아낼 수없는 것.
필요한 경우 더 많은 정보를 제공 할 수 있습니다.
왜 'characterObject'에서'super.paint'를 호출하고 있습니까? 이것은 사용자 정의 그림이 작동하는 방식이 아닙니다. 페인팅 프로세스를 제어하지 않으면 API는 – MadProgrammer