java 卡片布局问题

在Windows桌面上单击鼠标右键再选择属性这个窗口的上面有"主题""桌面""屏幕保护程序"等之类的卡片布局窗口请问怎么用JAVA实现这种卡片布局呢?请高手指点.... 在 Windows桌面上 单击鼠标右键 再选择属性 这个窗口的上面有
"主题" "桌面" "屏幕保护程序" 等 之类的卡片布局窗口 请问怎么用JAVA实现这种卡片布局呢? 请高手指点.
展开
 我来答
beyondtm
2007-11-09 · TA获得超过351个赞
知道答主
回答量:401
采纳率:0%
帮助的人:0
展开全部
先添加一个面板,把布局设置成CardLayout然后再向这个面板中添加新的面板。。就可以了。。。然后面板的转换用按钮做,给按钮添加单击事件。

这是用面板布局做的一个简单示例,你可以看一下,在JBUilder里面写的,可能不能运行。但你可以借鉴一下。
package jiemian;

import java.awt.BorderLayout;
import java.awt.Dimension;

import javax.swing.JFrame;
import javax.swing.JPanel;
import java.awt.CardLayout;
import javax.swing.JLabel;
import java.awt.Rectangle;
import javax.swing.JTextField;
import javax.swing.JPasswordField;
import javax.swing.JButton;
import javax.swing.JRadioButton;
import javax.swing.JSpinner;
import javax.swing.ButtonGroup;
import javax.swing.JComboBox;
import javax.swing.JList;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.SpinnerNumberModel;
import javax.swing.JOptionPane;
import javax.swing.JCheckBox;

/**
* <p>Title: </p>
*
* <p>Description: </p>
*
* <p>Copyright: Copyright (c) 2007</p>
*
* <p>Company: </p>
*
* @author not attributable
* @version 1.0
*/
public class Frame2 extends JFrame {
JPanel contentPane;
BorderLayout borderLayout1 = new BorderLayout();
JPanel jPanel1 = new JPanel();
CardLayout cardLayout1 = new CardLayout();
JPanel jPanel2 = new JPanel();
JPanel jPanel3 = new JPanel();
JPanel jPanel4 = new JPanel();
JLabel jLabel1 = new JLabel();
JTextField jTextField1 = new JTextField();
JLabel jLabel2 = new JLabel();
JPasswordField jPasswordField1 = new JPasswordField();
JButton jButton1 = new JButton();
JLabel jLabel3 = new JLabel();
JLabel jLabel4 = new JLabel();
JRadioButton jRadioButton1 = new JRadioButton();
JRadioButton jRadioButton2 = new JRadioButton();
JSpinner jSpinner1 = new JSpinner(new SpinnerNumberModel(25,18,55,1));
JButton jButton2 = new JButton();
JButton jButton3 = new JButton();
ButtonGroup buttonGroup1 = new ButtonGroup();
JLabel jLabel5 = new JLabel();
JLabel jLabel6 = new JLabel();
String[] zhiye={"学生","教室","工程师","医生"};
JComboBox jComboBox1 = new JComboBox(zhiye);
String[] gongzi={"1000以下","1000-2000","2000-3000","3000-5000","5000以上"};
JList jList1 = new JList(gongzi);
JButton jButton4 = new JButton();
JButton jButton5 = new JButton();
JLabel jLabel7 = new JLabel();
JCheckBox jCheckBox1 = new JCheckBox();
JCheckBox jCheckBox2 = new JCheckBox();
JCheckBox jCheckBox3 = new JCheckBox();
JCheckBox jCheckBox4 = new JCheckBox();

public Frame2() {
try {
setDefaultCloseOperation(EXIT_ON_CLOSE);
jbInit();
} catch (Exception exception) {
exception.printStackTrace();
}
}

/**
* Component initialization.
*
* @throws java.lang.Exception
*/
private void jbInit() throws Exception {
contentPane = (JPanel) getContentPane();
contentPane.setLayout(borderLayout1);
setSize(new Dimension(400, 300));
setTitle("step 1 of 3");
jPanel1.setLayout(cardLayout1);
jPanel2.setLayout(null);
jPanel3.setLayout(null);
jPanel4.setLayout(null);
jLabel1.setText("姓名:");
jLabel1.setBounds(new Rectangle(20, 24, 81, 31));
jTextField1.setBounds(new Rectangle(124, 23, 130, 33));
jLabel2.setText("密码:");
jLabel2.setBounds(new Rectangle(20, 81, 81, 30));
jPasswordField1.setBounds(new Rectangle(124, 79, 125, 31));
jButton1.setBounds(new Rectangle(126, 151, 100, 34));
jButton1.setText("下一步");
jButton1.addActionListener(new Frame2_jButton1_actionAdapter(this));
jLabel3.setText("性别");
jLabel3.setBounds(new Rectangle(34, 25, 89, 33));
jLabel4.setText("年龄");
jLabel4.setBounds(new Rectangle(34, 99, 89, 32));
jRadioButton1.setText("男");
jRadioButton1.setBounds(new Rectangle(136, 33, 65, 32));
jRadioButton2.setText("女");
jRadioButton2.setBounds(new Rectangle(207, 33, 65, 32));
jSpinner1.setBounds(new Rectangle(133, 96, 125, 36));
jButton2.setBounds(new Rectangle(160, 191, 93, 32));
jButton2.setText("下一步");
jButton2.addActionListener(new Frame2_jButton2_actionAdapter(this));
jButton3.setBounds(new Rectangle(38, 191, 89, 31));
jButton3.setText("上一步");
jButton3.addActionListener(new Frame2_jButton3_actionAdapter(this));
jLabel5.setText("职业");
jLabel5.setBounds(new Rectangle(31, 23, 93, 37));
jLabel6.setText("工资");
jLabel6.setBounds(new Rectangle(30, 61, 93, 33));
jComboBox1.setBounds(new Rectangle(115, 28, 112, 32));
jList1.setSelectedIndex(0);
jList1.setBounds(new Rectangle(113, 70, 112, 93));
jButton4.setBounds(new Rectangle(54, 180, 83, 37));
jButton4.setText("上一步");
jButton4.addActionListener(new Frame2_jButton4_actionAdapter(this));
jButton5.setBounds(new Rectangle(233, 181, 83, 36));
jButton5.setText("提交");
jButton5.addActionListener(new Frame2_jButton5_actionAdapter(this));
jLabel7.setText("爱好");
jLabel7.setBounds(new Rectangle(257, 28, 74, 30));
jCheckBox1.setText("音乐");
jCheckBox1.setBounds(new Rectangle(270, 56, 89, 30));
jCheckBox2.setText("体育");
jCheckBox2.setBounds(new Rectangle(270, 92, 87, 28));
jCheckBox3.setText("计算机");
jCheckBox3.setBounds(new Rectangle(270, 125, 82, 22));
jCheckBox4.setText("英语");
jCheckBox4.setBounds(new Rectangle(270, 153, 88, 24));
contentPane.add(jPanel1, java.awt.BorderLayout.CENTER);
jPanel1.add(jPanel2, "one");
jPanel2.add(jLabel1);
jPanel2.add(jTextField1);
jPanel2.add(jLabel2);
jPanel2.add(jPasswordField1);
jPanel2.add(jButton1);
jPanel1.add(jPanel3, "two");
jPanel3.add(jLabel3);
jPanel3.add(jLabel4);
jPanel3.add(jRadioButton1);
jPanel3.add(jRadioButton2);
jPanel3.add(jSpinner1);
jPanel3.add(jButton2);
jPanel3.add(jButton3);
jPanel4.add(jLabel5);
jPanel4.add(jComboBox1);
jPanel4.add(jList1);
jPanel4.add(jLabel6);
jPanel4.add(jLabel7);
jPanel4.add(jButton4);
jPanel4.add(jButton5);
jPanel4.add(jCheckBox1);
jPanel4.add(jCheckBox2);
jPanel4.add(jCheckBox3);
jPanel4.add(jCheckBox4);
buttonGroup1.add(jRadioButton1);
buttonGroup1.add(jRadioButton2);
jPanel1.add(jPanel4, "three");
}

public void jButton1_actionPerformed(ActionEvent e) {
cardLayout1.show(jPanel1,"two");
setTitle("step 2 of 3");
}

public void jButton3_actionPerformed(ActionEvent e) {
cardLayout1.show(jPanel1,"one");
setTitle("step 1 of 3");
}

public void jButton2_actionPerformed(ActionEvent e) {
cardLayout1.show(jPanel1,"three");//面板的转换
setTitle("step 3 of 3");
}

public void jButton4_actionPerformed(ActionEvent e) {
cardLayout1.show(jPanel1,"two");
setTitle("step 2 of 3");
}

public void jButton5_actionPerformed(ActionEvent e) {
String xinxi=new String();
xinxi+="姓名: ";
xinxi+=jTextField1.getText()+"\n";
xinxi+="性别: ";
if(jRadioButton1.isSelected()){
xinxi += "男 " + "\n";
if (jRadioButton2.isSelected()) {
xinxi+="女"+"\n";
}
}
xinxi+="年龄: ";
xinxi+=jSpinner1.getValue().toString()+"\n";
xinxi+="工资: ";
xinxi+=jComboBox1.getSelectedItem().toString()+"\n";
xinxi+="职业: ";
xinxi+=jList1.getSelectedValue().toString()+"\n";
xinxi+="爱好: "+"\n";
if(jCheckBox1.isSelected()){
xinxi+=" 音乐"+"\n";
}
if(jCheckBox2.isSelected()){
xinxi+=" 体育"+"\n";
}
if(jCheckBox3.isSelected()){
xinxi+=" 计算机"+"\n";
}
if(jCheckBox4.isSelected()){
xinxi+=" 英语"+"\n";
}

JOptionPane.showMessageDialog(this,xinxi);

}
}

class Frame2_jButton5_actionAdapter implements ActionListener {
private Frame2 adaptee;
Frame2_jButton5_actionAdapter(Frame2 adaptee) {
this.adaptee = adaptee;
}

public void actionPerformed(ActionEvent e) {
adaptee.jButton5_actionPerformed(e);
}
}

class Frame2_jButton4_actionAdapter implements ActionListener {
private Frame2 adaptee;
Frame2_jButton4_actionAdapter(Frame2 adaptee) {
this.adaptee = adaptee;
}

public void actionPerformed(ActionEvent e) {
adaptee.jButton4_actionPerformed(e);
}
}

class Frame2_jButton2_actionAdapter implements ActionListener {
private Frame2 adaptee;
Frame2_jButton2_actionAdapter(Frame2 adaptee) {
this.adaptee = adaptee;
}

public void actionPerformed(ActionEvent e) {
adaptee.jButton2_actionPerformed(e);
}
}

class Frame2_jButton3_actionAdapter implements ActionListener {
private Frame2 adaptee;
Frame2_jButton3_actionAdapter(Frame2 adaptee) {
this.adaptee = adaptee;
}

public void actionPerformed(ActionEvent e) {
adaptee.jButton3_actionPerformed(e);
}
}

class Frame2_jButton1_actionAdapter implements ActionListener {
private Frame2 adaptee;
Frame2_jButton1_actionAdapter(Frame2 adaptee) {
this.adaptee = adaptee;
}

public void actionPerformed(ActionEvent e) {
adaptee.jButton1_actionPerformed(e);
}
}
henterji
2007-11-09 · TA获得超过2973个赞
知道大有可为答主
回答量:1835
采纳率:0%
帮助的人:1878万
展开全部
楼主说的应该是JTabbedPane吧,给你个小程序研究下

import java.awt.BorderLayout;
import java.awt.Container;

import javax.swing.JApplet;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JTabbedPane;
import javax.swing.JTextField;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

public class TabbedPane1 extends JApplet {
private String[] flavors = { "Chocolate", "Strawberry",
"Vanilla Fudge Swirl", "Mint Chip", "Mocha Almond Fudge",
"Rum Raisin", "Praline Cream", "Mud Pie" };

private JTabbedPane tabs = new JTabbedPane();

private JTextField txt = new JTextField(20);

public void init() {
for (int i = 0; i < flavors.length; i++)
tabs.addTab(flavors[i], new JButton("Tabbed pane " + i));
tabs.addChangeListener(new ChangeListener() {
public void stateChanged(ChangeEvent e) {
txt.setText("Tab selected: " + tabs.getSelectedIndex());
}
});
Container cp = getContentPane();
cp.add(BorderLayout.SOUTH, txt);
cp.add(tabs);
}

public static void main(String[] args) {
run(new TabbedPane1(), 350, 200);
}

public static void run(JApplet applet, int width, int height) {
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().add(applet);
frame.setSize(width, height);
applet.init();
applet.start();
frame.setVisible(true);
}
}
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式