اخبار و اطلاعات مربوط به دروس

در این وبلاگ مباحث مرتبط با دروس تدریسی توسط اینجانب پیگیری می شود.

اخبار و اطلاعات مربوط به دروس

در این وبلاگ مباحث مرتبط با دروس تدریسی توسط اینجانب پیگیری می شود.

هدیه ای از طرف دانشجویان
Mbt925.ir

برنامه نویسی پیشرفته - مثال نوشته شده از CardLayout

چهارشنبه, ۲۹ ارديبهشت ۱۳۹۵، ۰۶:۵۰ ب.ظ

مثال نوشته شده از CardLayout سر کلاس رو می تونید در ادامه مشاهده کنید:

public class MainWindow extends JFrame {

public MainWindow() {
super("My first JFrame");

CardLayout cardLayout= new CardLayout();
JPanel cardPanel= new JPanel(cardLayout);

// center panel
JPanel centerPanel= new JPanel();
centerPanel.setLayout(new BoxLayout(centerPanel, BoxLayout.PAGE_AXIS));
centerPanel.add(new JButton("Button 1"));
centerPanel.add(new JButton("Button 2"));
centerPanel.add(Box.createRigidArea(new Dimension(0, 10)));
centerPanel.add(new JButton("Button 3"));
cardPanel.add(centerPanel, "page1");
// ===========================
JPanel bottomPanel= new JPanel();
bottomPanel.setLayout(new BoxLayout(bottomPanel, BoxLayout.LINE_AXIS));

bottomPanel.add(new JButton("Button 1"));
bottomPanel.add(new JButton("Button 2"));
bottomPanel.add(new JButton("Button 3"));
cardPanel.add(bottomPanel, "page2");

getContentPane().add(cardPanel, BorderLayout.CENTER);

JPanel toolbarPanel= new JPanel(new FlowLayout());
JButton preButton= new JButton("Pre");
preButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
cardLayout.previous(cardPanel);
}
});
toolbarPanel.add(preButton);
JButton nextButton= new JButton("Next");
nextButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
cardLayout.next(cardPanel);
}
});
toolbarPanel.add(nextButton);
getContentPane().add(toolbarPanel, BorderLayout.PAGE_END);

pack();
setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
setVisible(true);
}
}
  • بیگلری

نظرات  (۰)

هیچ نظری هنوز ثبت نشده است

ارسال نظر

ارسال نظر آزاد است، اما اگر قبلا در بیان ثبت نام کرده اید می توانید ابتدا وارد شوید.
شما میتوانید از این تگهای html استفاده کنید:
<b> یا <strong>، <em> یا <i>، <u>، <strike> یا <s>، <sup>، <sub>، <blockquote>، <code>، <pre>، <hr>، <br>، <p>، <a href="" title="">، <span style="">، <div align="">
تجدید کد امنیتی