// 初始化各种按钮
JCheckBox checkBox = new JCheckBox("复选按钮");
JButton button = new JButton("打开文件");
button.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
JFileChooser file = new JFileChooser();
int result = file.showOpenDialog(new JPanel());
if (result ==file.APPROVE_OPTION)
{
String fileName = file.getSelectedFile().getName();
String dir = file.getCurrentDirectory().toString();
JOptionPane.showConfirmDialog(null,dir+"\\"+fileName,"选择的文件",JOptionPane.YES_OPTION);
}
}
});
JToggleButton toggleButton = new JToggleButton("双态按钮");
ButtonGroup buttonGroup = new ButtonGroup();
JRadioButton radioButton1 = new JRadioButton("单选按钮1",false);
JRadioButton radioButton2 = new JRadioButton("单选按钮2",false);
////////////////////////////////////////////////////////////////////////////
/**
* 最左边模块,继承JPanel,初始化内容为JTree
* JPanel--+
* --JTree
*/
class LeftPanel extends JPanel
{
private int i = 0;
public LeftPanel()
{
DefaultMutableTreeNode root = new DefaultMutableTreeNode("Root");
DefaultMutableTreeNode child = new DefaultMutableTreeNode("Child");
DefaultMutableTreeNode select = new DefaultMutableTreeNode("select");
DefaultMutableTreeNode child1 = new DefaultMutableTreeNode(""+i);
////////////////////////////////////////////////////////////////////////////
/**
* 最下面层模块,继承JPanel,初始化内容为进度条,并由定时器控制
* JPanel--+
* --JProcessBar --Timer
*/
class BottomPanel extends JPanel
{
private JProgressBar pb;
public BottomPanel()
{
pb = new JProgressBar();
pb.setPreferredSize(new Dimension(680,20));
// 设置定时器,用来控制进度条的处理
Timer time = new Timer(1,new ActionListener()
{
int counter = 0;
public void actionPerformed(ActionEvent e)
{
counter++;
pb.setValue(counter);
Timer t = (Timer)e.getSource();