浏览 4183 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
|
|
---|---|
作者 | 正文 |
发表时间:2008-07-07
下面是程序代码: public class AlertFrame extends JFrame implements ActionListener{ private static final long serialVersionUID = 1L; private static int count = 1; private JTextArea detailTxa; private JScrollPane jScrollPane1; private JLabel errolLbl; private JButton cancelBtn; private JButton detailBtn; private String simpleMsg = ""; private String detailMsg = ""; public AlertFrame(){ super(); } public AlertFrame(String simpleMsg,String detailMsg){ super("系统消息"); this.simpleMsg = simpleMsg; this.detailMsg = detailMsg; init(); } public void init(){ WindowUtilities.setNativeLookAndFeel(); setSize(480,260); setResizable(true); Box box = new Box(BoxLayout.Y_AXIS); setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); setLayout(new BorderLayout()); JPanel centerPanel = new JPanel(new BorderLayout()); Box centerBox = new Box(BoxLayout.X_AXIS); centerBox.add(new JLabel(" ")); errolLbl = new JLabel(simpleMsg); centerBox.add(errolLbl); centerBox.add(new JLabel(" ")); JLabel titleLbl = new JLabel(" 系统消息 "); centerPanel.add(centerBox, BorderLayout.CENTER); centerPanel.add(titleLbl, BorderLayout.NORTH); JPanel bottomPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); cancelBtn = new JButton(" 取消 "); cancelBtn.addActionListener(this); detailBtn = new JButton("详细信息>>"); detailBtn.addActionListener(this); bottomPanel.add(cancelBtn); bottomPanel.add(detailBtn); centerPanel.add(bottomPanel , BorderLayout.SOUTH); detailTxa = new JTextArea(10,25); detailTxa.setText(detailMsg); detailTxa.setVisible(false); jScrollPane1 = new JScrollPane(detailTxa); jScrollPane1.setVisible(false); box.add(centerPanel); box.add(jScrollPane1); this.add(box); setVisible(true); } public void actionPerformed(ActionEvent e) { if(e.getSource() == cancelBtn){ this.dispose(); }else{ if((count%2) == 0){ this.jScrollPane1.setVisible(false); count++; } else{ this.jScrollPane1.setVisible(true); count++; } } } } 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |
发表时间:2008-07-07
validate
public void validate()验证此容器及其所有子组件。 使用 validate 方法会使容器再次布置其子组件。已经显示容器后,在修改此容器的子组件的时候(在容器中添加或移除组件,或者更改与布局相关的信息),应该调用上述方法。 如果此 Container 无效,则此方法将调用 validateTree 方法,并将此 Container 标记为有效。否则不执行任何动作。 |
|
返回顶楼 | |