62,626
社区成员
发帖
与我相关
我的任务
分享public class Frame extends JFrame implements PanelSwitch {
private static final long serialVersionUID = -1629925106866926779L;
private static final String CARD_HOME = "home";
private static final String CARD_ROLECALL = "roleCall";
private static final String CARD_SESSION = "session";
private static final String CARD_SETTING = "setting";
private JPanel homePanel;
private JPanel rolecallPanel;
private JPanel sessionPanel;
private JPanel settingPanel;
private JPanel mainPanel = new JPanel();
private CardLayout layout = new CardLayout();
private Conference conference;
public Frame() {
homePanel = new HomePanel(this);
rolecallPanel = new RolecallPanel(this);
sessionPanel = new SessionPanel(this);
settingPanel = new SessionPanel(this);
initFrame();
}
private void initFrame() {
setLayout(layout);
add(homePanel, CARD_HOME);
add(rolecallPanel, CARD_ROLECALL);
add(sessionPanel, CARD_SESSION);
add(settingPanel, CARD_SETTING);
setVisible(true);
}
public void switch_rolecallPanel() {
layout.show(this, CARD_ROLECALL);
}
public void switch_sessionPanel() {
layout.show(this, CARD_SESSION);
}
public void switch_homePanel() {
layout.show(this, CARD_HOME);
}
public void switch_settingPanel() {
layout.show(this, CARD_SETTING);
}
public static void main(String [] args) {
SwingConsole.run(new Frame());
// 一个辅助类,用于设置JFrame的title, height, width等属性
}
}public class HomePanel extends JPanel {
private static final long serialVersionUID = -2977633553899021068L;
private JLabel la_ConfName;
private JLabel la_ConfTopic;
private PanelSwitch frame;
private JButton bt_roleCallStart;
private JButton bt_settings;
private ActionListener lis_roleCallStart = new ActionListener() {
public void actionPerformed(ActionEvent e) {
frame.switch_rolecallPanel();
}
};
private ActionListener lis_settings = new ActionListener() {
public void actionPerformed(ActionEvent e) {
frame.switch_settingPanel();
}
};
private Conference conferenceSetting;
private BorderLayout layout = new BorderLayout();
public HomePanel(PanelSwitch frame) {
this.frame = frame;
initTextField();
initButtons();
initProductInfo();
setLayout(layout);
setVisible(true);
validate();
}
private void initTextField() {
la_ConfName = new JLabel();
la_ConfName.setFont(GraphicsConfig.getTitleFont());
la_ConfName.setVisible(true);
la_ConfTopic = new JLabel();
la_ConfTopic.setFont(GraphicsConfig.getTitleFont());
la_ConfTopic.setVisible(true);
//// FIXME: 7/30/16
// la_ConfName.setText(conferenceSetting.getName());
la_ConfName.setText("Title");
// la_ConfTopic.setText(conferenceSetting.getTopic());
la_ConfTopic.setText("subTitle");
JPanel confInfo = new JPanel();
confInfo.setLayout(new FlowLayout());
confInfo.add(la_ConfName);
confInfo.add(la_ConfTopic);
confInfo.setVisible(true);
confInfo.validate();
add(confInfo, BorderLayout.NORTH);
}
private void initButtons() {
bt_roleCallStart = new JButton("Start Session");
bt_roleCallStart.addActionListener(lis_roleCallStart);
// bt_roleCallStart.setVisible(true);
bt_settings = new JButton("Settings");
bt_settings.addActionListener(lis_settings);
// bt_roleCallStart.setVisible(true);
JPanel buttons = new JPanel();
buttons.setLayout(new BoxLayout(buttons, BoxLayout.Y_AXIS));
buttons.add(bt_settings);
buttons.add(Box.createVerticalStrut(12));
buttons.add(bt_roleCallStart);
buttons.setVisible(true);
buttons.validate();
add(buttons, BorderLayout.EAST);
}
private void initProductInfo() {
JLabel groupInfo = new JLabel("Product designed by");
JLabel groupPhoto = new JLabel(new ImageIcon(getClass().getResource("/logo/logo.jpg")));
JPanel info = new JPanel();
info.setLayout(new BoxLayout(info, BoxLayout.Y_AXIS));
info.add(groupInfo);
info.add(Box.createVerticalGlue());
info.add(groupPhoto);
info.setVisible(true);
info.validate();
add(info, BorderLayout.WEST);
}
}