java.awt.CardLayout.<init>()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(11.9k)|赞(0)|评价(0)|浏览(130)

本文整理了Java中java.awt.CardLayout.<init>()方法的一些代码示例,展示了CardLayout.<init>()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。CardLayout.<init>()方法的具体详情如下:
包路径:java.awt.CardLayout
类名称:CardLayout
方法名:<init>

CardLayout.<init>介绍

[英]Creates a new card layout with gaps of size zero.
[中]创建间隙为零的新卡片布局。

代码示例

代码示例来源:origin: pedrovgs/AndroidWiFiADB

public void createAndShowGUI() {
 cards = new JPanel(new CardLayout());
 createNoDevicesPanel();
 createTableDevices();
 cards.add(panelDevices, CARD_DEVICES);
 cards.add(panelNoDevices, CARD_NO_DEVICES);
 parentContainer.add(cards, BorderLayout.PAGE_START);
 setupUi();
}

代码示例来源:origin: kiegroup/optaplanner

private JPanel createMiddlePanel() {
  middlePanel = new JPanel(new CardLayout());
  JPanel usageExplanationPanel = new JPanel(new BorderLayout(5, 5));
  ImageIcon usageExplanationIcon = new ImageIcon(getClass().getResource(solutionPanel.getUsageExplanationPath()));
  JLabel usageExplanationLabel = new JLabel(usageExplanationIcon);
  // Allow splitPane divider to be moved to the right
  usageExplanationLabel.setMinimumSize(new Dimension(100, 100));
  usageExplanationPanel.add(usageExplanationLabel, BorderLayout.CENTER);
  JPanel descriptionPanel = new JPanel(new BorderLayout(2, 2));
  descriptionPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
  descriptionPanel.add(new JLabel("Example description"), BorderLayout.NORTH);
  JTextArea descriptionTextArea = new JTextArea(8, 70);
  descriptionTextArea.setEditable(false);
  descriptionTextArea.setText(solutionBusiness.getAppDescription());
  descriptionPanel.add(new JScrollPane(descriptionTextArea,
      JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED), BorderLayout.CENTER);
  usageExplanationPanel.add(descriptionPanel, BorderLayout.SOUTH);
  middlePanel.add(usageExplanationPanel, "usageExplanationPanel");
  JComponent wrappedSolutionPanel;
  if (solutionPanel.isWrapInScrollPane()) {
    wrappedSolutionPanel = new JScrollPane(solutionPanel);
  } else {
    wrappedSolutionPanel = solutionPanel;
  }
  middlePanel.add(wrappedSolutionPanel, "solutionPanel");
  return middlePanel;
}

代码示例来源:origin: stackoverflow.com

private CardLayout cardlayout = new CardLayout();
private JPanel cards = new JPanel(cardlayout);
 cards.add(createUserAgreePanel(), USER_AGREEMENT);
 cards.add(createUserInfoPanel(), USER_INFO);
 cards.add(createEnrollmentPanel(), ENROLLMENT);
 setLayout(new BorderLayout());
 add(cards, BorderLayout.CENTER);
 JPanel enrol = new JPanel();
 enrol.add(new JLabel("Enrollment"));
 return enrol;
 JPanel userAgree = new JPanel();
 userAgree.add(new JLabel("User Agreement"));
 return userAgree;
 cardlayout.show(cards, key);

代码示例来源:origin: stackoverflow.com

JFrame frame = new JFrame("Layout Example");
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
borderPanel.setBackground(Color.WHITE);
for (int i = 0; i < 5; i++) {
  buttons[i] = new JButton(borderConstraints[i]);
  borderPanel.add(buttons[i], borderConstraints[i]);
contentPane.add(borderPanel);
flowPanel = new JPanel(new FlowLayout(
      FlowLayout.CENTER, hGap, vGap));
flowPanel.setBorder(
gridPanel.setBackground(Color.WHITE);
for (int i = 8; i < 12; i++) {
  buttons[i] = new JButton(Integer.toString(i));
cardPanel = new JPanel(new CardLayout(hGap, vGap));
cardPanel.setBorder(
  BorderFactory.createTitledBorder("CardLayout"));
frame.pack();
frame.setLocationByPlatform(true);
frame.setVisible(true);

代码示例来源:origin: geotools/geotools

private void initComponents() {
  JPanel buttonPanel = new JPanel();
  Box buttonBox = new Box(BoxLayout.X_AXIS);
  cardPanel = new JPanel();
  cardPanel.setBorder(new EmptyBorder(new Insets(5, 10, 5, 10)));
  cardLayout = new CardLayout();
  cardPanel.setLayout(cardLayout);
  backButton = new JButton("Back");
  nextButton = new JButton("Next");
  finishButton = new JButton("Finish");
  cancelButton = new JButton("Cancel");
  backButton.addActionListener(controller);
  nextButton.addActionListener(controller);
  finishButton.addActionListener(controller);
  cancelButton.addActionListener(controller);
  buttonPanel.setLayout(new BorderLayout());
  buttonPanel.add(new JSeparator(), BorderLayout.NORTH);
  buttonBox.setBorder(new EmptyBorder(new Insets(5, 10, 5, 10)));
  buttonBox.add(backButton);
  buttonBox.add(Box.createHorizontalStrut(10));
  buttonBox.add(nextButton);
  buttonBox.add(Box.createHorizontalStrut(30));
  buttonBox.add(finishButton);
  buttonBox.add(Box.createHorizontalStrut(10));
  buttonBox.add(cancelButton);
  buttonPanel.add(buttonBox, java.awt.BorderLayout.EAST);
  getContentPane().add(buttonPanel, java.awt.BorderLayout.SOUTH);
  getContentPane().add(new JScrollPane(cardPanel), java.awt.BorderLayout.CENTER);
}

代码示例来源:origin: kiegroup/optaplanner

private JComponent createToolBar() {
  JPanel toolBar = new JPanel();
  GroupLayout toolBarLayout = new GroupLayout(toolBar);
  toolBar.setLayout(toolBarLayout);
  if (solutionBusiness.hasImporter()) {
    importAction = new ImportAction();
    importButton = new JButton(importAction);
  } else {
    importButton = null;
  JButton openButton = new JButton(openAction);
  saveAction = new SaveAction();
  saveAction.setEnabled(false);
  JButton saveButton = new JButton(saveAction);
  JButton exportButton;
  if (solutionBusiness.hasExporter()) {
  JPanel solvePanel = new JPanel(new CardLayout());
  solveAction = new SolveAction();
  solveAction.setEnabled(false);

代码示例来源:origin: stackoverflow.com

public class MyClass implements ActionListener {
 private CardLayout cardLayout = new CardLayout();
 private JPanel cards = new JPanel(cardLayout);
 public void setup(){
   JFrame f = new JFrame("Start ");
   JPanel card1 = new JPanel();
   JPanel card2 = new JPanel();
   // cards = new JPanel(new CardLayout());
   JButton Card1Button = new JButton("Start");
   card1.add(Card1Button);
   JButton Card2Button = new JButton("Exit");
   card2.add(Card2Button);
   cards.add(card1, "C1");
   cards.add(card2, "C2");
   f.add(cards, BorderLayout.CENTER);
   f.setTitle("Furutsu");
   f.setSize(500, 300);
   f.setLocationRelativeTo(null);
   f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
   f.setVisible(true);
 }

代码示例来源:origin: stackoverflow.com

final JPanel mainPanel=new JPanel();
 JPanel panelOne=new JPanel();
 JPanel panelTwo=new JPanel();
 final CardLayout card=new CardLayout();
 mainPanel.setLayout(card);
 mainPanel.add(panelOne, "one"); // id one refers panelOne
 mainPanel.add(panelTwo, "two"); // id two refers panelTwo
 panelOne.add(new JLabel("first panel"));
 JButton btn1=new JButton("Show second");
 panelOne.add(btn1);
 btn1.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent ae){
 card.show(mainPanel, "two"); // shows panelTwo
 }});
panelTwo.add(new JLabel("second panel"));
 JButton btn2=new JButton("Show First");
 panelTwo.add(btn2);
 btn2.addActionListener(new ActionListener(){public void actionPerformed(ActionEvent ae){
 card.show(mainPanel, "one"); // shows panelOne
 }});

代码示例来源:origin: stackoverflow.com

//make it a sub class of JPanel for easier implementation. 
public class Cell extends JPanel{

  public  Cell(){

    JPanel firstPanel = new JPanel();
    //add a lable just so something is displayed
    firstPanel.add(new JLabel(("Panel 1"))); 
    JPanel secondPanel = new JPanel();
    JPanel thridpanel = new JPanel();

    CardLayout cardLayout = new CardLayout();
    /* assign the card layout */
    setLayout(cardLayout);

    /* add the different panels to the container panel and show the initial one */
    add(firstPanel, "firstPanel");
    add(secondPanel, "secondPanel");
    add(thridpanel, "thridpanel");
    cardLayout.show(this, "firstPanel");
  }
}

代码示例来源:origin: stackoverflow.com

CardLayout layout = new CardLayout();
JFrame frame = new JFrame();
frame.setLayout(layout);
JPanel panel1 = new JPanel();
JPanel panel2 = new JPanel();
frame.add(panel1, "first");
frame.add(panel2, "second");

代码示例来源:origin: stackoverflow.com

JFrame frame = new JFrame("Scrolling Shooter");

TitleScreen title = new TitleScreen(frame);
ScrollingShooter game = new ScrollingShooter(frame);

cards = new JPanel(new CardLayout());
cards.add(title, "title");
cards.add(game, "game");
cards.setOpaque(true);

cardLayout = (CardLayout) cards.getLayout();
cardLayout.first(cards);

frame.add(cards);
//...
frame.setResizable(false);
frame.setSize(width, height);
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLocationRelativeTo(null);
frame.setVisible(true);

代码示例来源:origin: stackoverflow.com

import java.awt.CardLayout;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JPanel;

public @SuppressWarnings("serial")
class SwappingComponent extends JPanel {
  private static final String SHOW = "show";
  private static final String HIDE = "hide";
  JComponent component;
  CardLayout cardLayout = new CardLayout();

  public SwappingComponent(JComponent component) {
    setLayout(cardLayout);
    this.component = component;
    add(component, SHOW);
    add(new JLabel(), HIDE);
  }

  public JComponent getComponent() {
    return component;
  }

  public void showComponent(boolean show) {
    String key = show ? SHOW : HIDE;
    cardLayout.show(this, key);
  }

}

代码示例来源:origin: stackoverflow.com

initComponents();
cards = new JPanel(new CardLayout());
add(cards);
setVisible(true);
cl.show(cards, cName);

代码示例来源:origin: stackoverflow.com

private JLabel jl1, jl2;
private JButton btn1, btn2;
private CardLayout cardLayout = new CardLayout();
      cardLayout.show(cardPanel, "1");
  btn2 = new JButton("Show Card 2");
  btn2.addActionListener(new ActionListener() {
      cardLayout.show(cardPanel, "2");
    public void run() {
      CardLayoutTest frame = new CardLayoutTest();
      frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
      frame.setVisible(true);

代码示例来源:origin: stackoverflow.com

import java.awt.CardLayout;
import java.awt.event.ActionEvent;

import javax.swing.*;

public class Main2 {
  public static void main(String[] args) {
   final JComboBox<String> myCombo = new JComboBox<String>(new String[]{"Foo", "Bar"});

   final CardLayout cardLayout = new CardLayout();
   final JPanel cardPanel = new JPanel(cardLayout);
   cardPanel.add(myCombo, "combo");
   cardPanel.add(new JLabel(), "empty");

   final JPanel mainPanel = new JPanel();
   mainPanel.add(new JButton(new AbstractAction("Toggle Combo") {

     @Override
     public void actionPerformed(ActionEvent evt) {
      cardLayout.next(cardPanel);
     }
   }));
   mainPanel.add(cardPanel);

   JOptionPane.showMessageDialog(null, mainPanel);
  }

}

代码示例来源:origin: stackoverflow.com

cards = new JPanel(new CardLayout() );
card_list = new JPanel[5];
JPanel card = new JPanel();
card.setName(text);
JButton btn = new JButton(text);
btn.addActionListener(this);

代码示例来源:origin: stackoverflow.com

private void displayGUI() {
  JFrame frame = new JFrame("eBookReader Button");
  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

  JPanel contentPane = new JPanel();
  contentPane.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
  contentPane.setLayout(new CardLayout());
  panel1 = new MyPanel(contentPane);
  contentPane.add(panel1, "Panel 1");
  frame.setContentPane(contentPane);
      // we need to increase the size of the panel so when we switch views we can see the viewer
  frame.setPreferredSize(new Dimension(2000, 700));
  frame.pack();
  frame.setLocationByPlatform(true);
  frame.setVisible(true);
}

代码示例来源:origin: org.zaproxy/zap

private JPanel getPanelContent() {
  if (panelContent == null) {
    panelContent = new JPanel(new CardLayout());
  }
  return panelContent;
}

代码示例来源:origin: stackoverflow.com

CardLayout card = new CardLayout();
JPanel mainPanel = new JPanel(card);
JPanel firstVisiblePanel = new JPanel();
Hex hex = new Hex();
Maze maze = new Maze();

public Center() {
  mainPanel.add(firstVisiblePanel, "initialPanel");
  mainPanel.add(hex, "hex");
  mainPanel.add(maze, "maze");

  final JButton jbtHex = new JButton("Hex");
  jbtHex.addActionListener(new ActionListener(){
    public void actionPerformed(ActionEvent e) {
      card.show(mainPanel, "hex");
    }
  });
  // do the same as above for the other panels.
  ....
  frame.add(mainPanel); <------- This is the ONLY panel you add to the frame.
  frame.setVisible(true); <----- Should be the LAST thing you do.
}

代码示例来源:origin: stackoverflow.com

bg.add( highScores );
JPanel buttons = new JPanel(new 
  FlowLayout(FlowLayout.CENTER, 5, 5));
buttons.add( game );
buttons.add( highScores );
JPanel gui = new JPanel(new BorderLayout(5,5));
gui.add(buttons, BorderLayout.SOUTH);
final CardLayout cl = new CardLayout();
final JPanel cards = new JPanel(cl);
gui.add(cards);
cards.add(new JLabel("Level 1"), "game");
  public void actionPerformed(ActionEvent ae) {
    if (game.isSelected()) {
      cl.show(cards, "game");
    } else {
      cl.show(cards, "scores");

相关文章