そのため、クラスではJavaプログラムを作成しています。JFrameでpaint(Graphics g)関数を使用しようとしています。私たちは過去(数週間前)にそれを試しましたが、以前は機能していました。しかし、今はそうではありません(またはどこかで間違いを犯しました)。paintComponent(Graphics g)も使用しようとしましたが、何も機能しないようです。これが私たちのコードです:
public class MainAc {
public static void main(String[] args) {
JFrame frame = new JFrame("Class Paint");
JButton button = new JButton("Click for more");
frame.setSize(800, 600);
frame.add(button);
frame.setLayout(null);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
button.setLayout(null);
button.setLocation(100,100);
button.setSize(200,100);
frame.setVisible(true);
}
public void paint(Graphics g){
g.drawString("Hello", 200, 50);
}
}