/** * Init JWhiteBoard interface * * @throws Exception */ public void go() throws Exception { if (!noChannel && !useState) channel.connect(groupName); mainFrame = new JFrame(); mainFrame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE); drawPanel = new DrawPanel(useState); drawPanel.setBackground(backgroundColor); subPanel = new JPanel(); mainFrame.getContentPane().add("Center", drawPanel); clearButton = new JButton("Clean"); clearButton.setFont(defaultFont); clearButton.addActionListener(this); leaveButton = new JButton("Exit"); leaveButton.setFont(defaultFont); leaveButton.addActionListener(this); subPanel.add("South", clearButton); subPanel.add("South", leaveButton); mainFrame.getContentPane().add("South", subPanel); mainFrame.setBackground(backgroundColor); clearButton.setForeground(Color.blue); leaveButton.setForeground(Color.blue); mainFrame.pack(); mainFrame.setLocation(15, 25); mainFrame.setBounds(new Rectangle(250, 250)); if (!noChannel && useState) { channel.connect(groupName, null, stateTimeout); } mainFrame.setVisible(true); }
public void disconnected() { connectButton.setText(CONNECT); state.setText("disconnected ok"); }
public void connected() { connectButton.setText(DISCONNECT); state.setText("connected ok"); }
public ControlPanel() { super(); // Layout the labels in a panel JPanel labelPane = new JPanel(); labelPane.setLayout(new GridLayout(0, 1)); labelPane.add(new JLabel("Message size")); labelPane.add(new JLabel("Current view")); labelPane.add(new JLabel("Throughput")); labelPane.add(new JLabel("Last view count")); colorPanel = new ColorPanel(); connectButton = new JButton(DISCONNECT); connectButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { JButton b = (JButton) e.getSource(); String current_state = b.getText(); if (CONNECT.equals(current_state)) { connect(); } else if (DISCONNECT.equals(current_state)) { disconnect(); } } }); transmit = new JButton(new TransmitAction()); labelPane.add(connectButton); labelPane.add(transmit); int size = 10; messageSize = new JTextField(size); messageSize.setText("" + mSize); messageSize.addActionListener( new ActionListener() { /** Invoked when an action occurs. */ public void actionPerformed(ActionEvent e) { mSize = Integer.parseInt(messageSize.getText()); } }); viewNumber = new JTextField(size); viewNumber.setEditable(false); throughput = new JTextField(size); throughput.setEditable(false); numMessagesInLastView = new JTextField(size); numMessagesInLastView.setEditable(false); state = new JTextField(size); state.setEditable(false); // Layout the text fields in a panel JPanel fieldPane = new JPanel(); fieldPane.setLayout(new GridLayout(0, 1)); fieldPane.add(messageSize); fieldPane.add(viewNumber); fieldPane.add(throughput); fieldPane.add(numMessagesInLastView); fieldPane.add(state); fieldPane.add(colorPanel); // Put the panels in another panel, labels on left, // text fields on right JPanel contentPane = new JPanel(); contentPane.setBorder(BorderFactory.createTitledBorder("Control")); contentPane.setLayout(new BorderLayout()); contentPane.add(labelPane, BorderLayout.CENTER); contentPane.add(fieldPane, BorderLayout.EAST); this.setLayout(new BorderLayout()); this.add(contentPane); }