카드 레이아웃이 무엇인지 알아 내려고 애 쓰고 있습니다. 나는 많은 기사를 읽고이 작은 예제를 구현하여 카드 레이아웃이 어떻게 작동하는지 살펴 보았다. 그러나 나는 주석 처리 된 몇 가지 방법을 이해할 수 없다. 누군가 제발 나를 도울 수 있습니까 (저는 커맨드 라인을 사용합니다).카드 레이아웃 사용 방법?
import java.util.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
class C_layout implements ActionListener
{
JButton b2;
JButton b1;
JFrame f1;
JPanel card1;
JPanel card2;
JPanel Jp;
void Example()
{
f1=new JFrame("CardLayout Exercise");
f1.setLocationRelativeTo(null);
f1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f1.setSize(500,500);
f1.setVisible(true);
Container cont=f1.getContentPane();
cont.setLayout(null);
Jp=new JPanel(new CardLayout()); //<-- How to implement card layout here (MAIN PANEL)
f1.add(Jp);
Jp.setLayout //<-- Not sure what means here ERROR
card1=new JPanel(); // First panel
Jp.add(card1);
card2=new JPanel(); // Second panel
Jp.add(card2);
JLabel lb1=new JLabel("This is the first Panel");
lb1.setBounds(250,100,100,30);
card1.add(lb1);
b1=new JButton("NEXT >>");
b1.setBounds(350,400,100,30);
b1.addActionListener(this);
card1.add(b1);
JLabel lb2=new JLabel("This is the second Panel");
lb2.setBounds(250,100,100,30);
card2.add(lb2);
b2=new JButton("<< PREV");
b2.setBounds(250,300,100,30);
b2.addActionListener(this);
card2.add(b2);
}
public void actionPerformed(ActionEvent e)
{
if(e.getSource()==b1)
{
CardLayout cardLayout = (CardLayout) Jp.getLayout();
cardLayout.show(card2,"2");
}
if(e.getSource()==b2)
{
// I still haven't implemented this action listener
}
}
}
class LayoutDemo1
{
public static void main(String[] args)
{
C_layout c=new C_layout();
c.Example();
}
}
가 대단히 감사합니다 자세한 내용은 How to Use CardLayout하세요! –
호프가 도움이 되었으면 좋겠다. – MadProgrammer
프레임을 보여주는 방법을 좀 더 설명해 주시겠습니까? 빈 프레임을 보여줍니다. 나는 CardLayout # show를 이해하지 못했다. –