import java.awt.*; import java.awt.event.*; import java.applet.Applet; import javax.swing.*; public class Test3 extends Applet implements ActionListener, KeyListener { private JPanel displayPanel; private JButton submitBT; private JButton passBT; private JCheckBox botCB; private JTextArea chatTA; private JScrollPane sp_chatTA; private JTextField chatTB; private JButton sendBT; private JTextArea historyTA; private JScrollPane sp_historyTA; private static final String ENABLE_BOT = "ENABLE BOT"; private static final String SUBMIT = "PLAY HAND"; private static final String PASS = "PASS HAND"; private static final String SEND = "SEND MSG"; private static final Font DEFAULT_FONT = new Font("Comic Sans", Font.BOLD, 12); public void init() { Test3Layout customLayout = new Test3Layout(); this.setBackground(Color.BLACK); setFont(DEFAULT_FONT); setLayout(customLayout); displayPanel = new JPanel(); displayPanel.setBackground(Color.GREEN); add(displayPanel); submitBT = new JButton(SUBMIT); submitBT.setBackground(Color.BLACK); submitBT.setForeground(Color.WHITE); submitBT.setActionCommand(SUBMIT); submitBT.addActionListener(this); add(submitBT); passBT = new JButton(PASS); passBT.setBackground(Color.BLACK); passBT.setForeground(Color.WHITE); passBT.setActionCommand(PASS); passBT.addActionListener(this); add(passBT); botCB = new JCheckBox(ENABLE_BOT); botCB.setBackground(Color.DARK_GRAY); botCB.setForeground(Color.WHITE); botCB.setActionCommand(ENABLE_BOT); botCB.addActionListener(this); add(botCB); chatTA = new JTextArea(""); chatTA.setEditable(false); chatTA.setFont(DEFAULT_FONT); sp_chatTA = new JScrollPane(chatTA); add(sp_chatTA); chatTB = new JTextField(""); chatTB.setFont(DEFAULT_FONT); chatTB.addKeyListener(this); chatTB.setFocusable(true); chatTB.requestFocus(); add(chatTB); sendBT = new JButton(SEND); sendBT.setBackground(Color.BLACK); sendBT.setForeground(Color.WHITE); sendBT.setActionCommand(SEND); sendBT.addActionListener(this); add(sendBT); historyTA = new JTextArea("Game History:"); historyTA.setEditable(false); historyTA.setFont(DEFAULT_FONT); sp_historyTA = new JScrollPane(historyTA); add(sp_historyTA); setSize(getPreferredSize()); } public static void main(String args[]) { Test3 applet = new Test3(); Frame window = new Frame("A$$HOLE APPLET TEST 3"); window.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); applet.init(); window.add("Center", applet); window.pack(); window.setVisible(true); } public void actionPerformed(ActionEvent e) { if(e.getActionCommand().equals(SUBMIT)) { //for testing...take out later chatTA.setText(SUBMIT + " was hit"); } else if(e.getActionCommand().equals(PASS)) { //for testing...take out later chatTA.setText(PASS + " was hit"); } else if(e.getActionCommand().equals(ENABLE_BOT)) { //for testing...take out later if(botCB.isSelected()) chatTA.setText("Bot was enabled"); else chatTA.setText("Bot was disabled"); } else if(e.getActionCommand().equals(SEND)) { //for testing...take out later chatTA.setText("User typed: " + chatTB.getText()); chatTB.setText(""); } } public void keyPressed(KeyEvent e) { if(e.getKeyCode() == e.VK_ENTER) { //for testing...take out later chatTA.setText("User typed: " + chatTB.getText()); chatTB.setText(""); } } public void keyReleased(KeyEvent e) { } public void keyTyped(KeyEvent e) { } } class Test3Layout implements LayoutManager { public Test3Layout() { } public void addLayoutComponent(String name, Component comp) { } public void removeLayoutComponent(Component comp) { } public Dimension preferredLayoutSize(Container parent) { Dimension dim = new Dimension(0, 0); Insets insets = parent.getInsets(); dim.width = 596 + insets.left + insets.right; dim.height = 436 + insets.top + insets.bottom; return dim; } public Dimension minimumLayoutSize(Container parent) { Dimension dim = new Dimension(0, 0); return dim; } public void layoutContainer(Container parent) { Insets insets = parent.getInsets(); Component c; c = parent.getComponent(0); if (c.isVisible()) {c.setBounds(insets.left+8,insets.top+8,584,312);} c = parent.getComponent(1); if (c.isVisible()) {c.setBounds(insets.left+8,insets.top+320,104,24);} c = parent.getComponent(2); if (c.isVisible()) {c.setBounds(insets.left+120,insets.top+320,120,24);} c = parent.getComponent(3); if (c.isVisible()) {c.setBounds(insets.left+248,insets.top+320,168,24);} c = parent.getComponent(4); if (c.isVisible()) {c.setBounds(insets.left+8,insets.top+344,416,64);} c = parent.getComponent(5); if (c.isVisible()) {c.setBounds(insets.left+8,insets.top+408,312,24);} c = parent.getComponent(6); if (c.isVisible()) {c.setBounds(insets.left+320,insets.top+408,104,24);} c = parent.getComponent(7); if (c.isVisible()) {c.setBounds(insets.left+424,insets.top+320,168,112);} } }