어떻게 스크롤 JFrame을 만들 수 있습니까? 이 코드는 스크롤 업하지 않습니다. 그래서 얼마 후 버튼이 사라졌습니다. 그럼 내가 어떻게 할 수 있니? 누구든지 나를 도울 수 있습니까?Java에서 게임용 JFrame 스크롤
import javax.swing.JFrame;
import javax.swing.*;
class c extends JFrame implements Runnable{
JButton b1;
c(){
b1=new JButton("Going Up");
b1.setBounds(150,600,100,50);
this.add(b1);
this.setSize(400,800);
this.setLayout(null);
this.setVisible(true);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public void run(){
try{
while(true)
{
b1.setLocation(b1.getX(),b1.getY()-2);
Thread.sleep(20);
}
}
catch(Exception ex){
}
}
public static void main(String[] args){
c a1 = new c();
Thread t1 = new Thread(a1);
t1.start();
}
}
'잠시 후에 버튼이 사라지면 '- y 값이 음수가됩니다. if 문을 추가하고 값을 0으로 재설정하십시오. – camickr