나는 단순한 MP3 플레이어를 만들기 시작하고있다. 나는 앞으로, 뒤로, 등의 놀이를 만들고있다 ... 버튼이지만 어떤 이유 때문에 첫 번째 버튼 만 나타나고 두 번째 버튼을 나타나게하고 그 위에 스크롤해야합니다. 너가 그걸 고칠 수 있다면, 좋을거야. 그리고 저는 play.jpg라는 이미지와 next.png라는 이미지 두 개를 사용하고 있습니다.JButton을 스크롤 할 때까지 보이지 않는다.
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Graphic extends JPanel{
JFrame f = new JFrame();
JPanel p = new JPanel(new GridBagLayout());
public Graphic(){
gui();
}
public void gui(){
f.setVisible(true);
f.setSize(1600,900);
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.add(p);
ppr(75,26,25,25,"pics/play.jpg");
//above is the play button
ppr(40,26,25,25,"pics/next.png");
// above is the button that wont appear until it is scrolled over (it is just to the left of the button above
}
public void ppr(int x, int y, int width, int height, String file){
p.setLayout(null);
Toolkit tool = Toolkit.getDefaultToolkit();
Image player = tool.getImage(file);
ImageIcon playbutton = new ImageIcon(player);
JButton play = new JButton(playbutton);
play.setBounds(x, y, width, height);
p.add(play);
// ********************** above is the the method that makes a button
}
public static void main(String args[]) {
new Graphic();
}
}
강조 : * 수동으로 크기를 조정하거나 구성 요소를 배치하지 마십시오. 대신 적절한 LayoutManager를 사용하십시오. – kleopatra