如何做一个向导页面的对话框,包含上一步、下一步之类的按钮

huoyin 2007-06-26 03:06:10
如题:
最好能给出源代码或者引用,谢谢。
...全文
335 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
boby 2007-06-26
  • 打赏
  • 举报
回复
http://java.sun.com/docs/books/tutorial/

huoyin 2007-06-26
  • 打赏
  • 举报
回复
你能给我一个link吗?
boby 2007-06-26
  • 打赏
  • 举报
回复
我都是在看sun的网上教程,那上面写得好,而且都有例子
huoyin 2007-06-26
  • 打赏
  • 举报
回复
多谢楼上的,另外你使用jdk1.5编译的吧,jdk1.4上有点问题我已经改好了。

顺便问一下,能不能给我推荐一本swing方面的好书,以前自己主要在做web方面的界面,对GUI很不熟悉
boby 2007-06-26
  • 打赏
  • 举报
回复
我是用CardLayout做的,不知道别人有没有更好的方法

我的做法大概如下:

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.*;
import javax.swing.*;

public class WizardTest extends JFrame implements ActionListener{
final static String TEXTPANEL = "0";
final static String BUTTONPANEL = "1";
final static String LABELPANEL = "2";

private JPanel mainPanel = new JPanel();
private JPanel panel1 = new JPanel();
private JPanel panel2 = new JPanel();
private JPanel panel3 = new JPanel();
private JPanel btnPanel = new JPanel();
private JButton nextBtn = new JButton("next");
private JButton backBtn = new JButton("back");
private int index = 0;

public WizardTest() {
this.setSize(500, 400);
this.setLayout(new BorderLayout());
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

backBtn.addActionListener(this);
nextBtn.addActionListener(this);

btnPanel.add(backBtn);
btnPanel.add(nextBtn);
panel1.add(new TextField("text Panel"));
panel2.add(new JButton("button Panel"));
panel3.add(new JLabel("label Panel"));

mainPanel.setLayout(new CardLayout());
mainPanel.add(panel1, TEXTPANEL);
mainPanel.add(panel2, BUTTONPANEL);
mainPanel.add(panel3, LABELPANEL);

this.add(mainPanel, BorderLayout.CENTER);
this.add(btnPanel, BorderLayout.SOUTH);
this.setVisible(true);
}



public void actionPerformed(ActionEvent e) {
CardLayout cl = (CardLayout)(mainPanel.getLayout());
if (e.getActionCommand().equals("next")) {
if (index <= Integer.valueOf(LABELPANEL)) {
index ++;
cl.show(mainPanel, Integer.toString(index));
if (index > Integer.valueOf(LABELPANEL))
index = Integer.valueOf(LABELPANEL);
}
}

if (e.getActionCommand().equals("back")) {
if (index >= Integer.valueOf(TEXTPANEL)) {
index --;
cl.show(mainPanel, Integer.toString(index));
if (index < Integer.valueOf(TEXTPANEL))
index = Integer.valueOf(TEXTPANEL);
}
}
System.out.println(index);
}

public static void main(String[] args) {
WizardTest at = new WizardTest();
}
}

62,623

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧