Advertisement
Guest User

Untitled

a guest
Mar 31st, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.41 KB | None | 0 0
  1. import java.awt.EventQueue;
  2.  
  3. import javax.swing.JFrame;
  4. import javax.swing.JTextField;
  5. import javax.swing.JButton;
  6. import java.awt.event.ActionListener;
  7. import java.awt.event.ActionEvent;
  8. import javax.swing.JTextPane;
  9. import javax.swing.JLabel;
  10. import javax.swing.JPasswordField;
  11. import javax.swing.JScrollPane;
  12. import javax.swing.JSeparator;
  13. import javax.swing.SwingConstants;
  14. import javax.swing.text.DefaultCaret;
  15. import javax.swing.JTextArea;
  16. import java.awt.Font;
  17.  
  18.  
  19. public class Console {
  20.  
  21. private JFrame frame;
  22. private JTextField usernameField;
  23. private JPasswordField passwordField;
  24. private JTextField commandBox;
  25. private static JScrollPane scroll;
  26. private static JTextArea chat;
  27. private static JLabel loginError;
  28.  
  29.  
  30. private static JLabel lblYes;
  31. private static JLabel lblNo;
  32.  
  33. private static MCBotMain bot = new MCBotMain();
  34.  
  35. /**
  36. * Launch the application.
  37. */
  38. public static void main(String[] args) {
  39.  
  40. bot.readWhitelist();
  41.  
  42. EventQueue.invokeLater(new Runnable() {
  43. public void run() {
  44. try {
  45. Console window = new Console();
  46. window.frame.setVisible(true);
  47. } catch (Exception e) {
  48. e.printStackTrace();
  49. }
  50. }
  51. });
  52. }
  53.  
  54. /**
  55. * Create the application.
  56. */
  57. public Console() {
  58. initialize();
  59. }
  60.  
  61. /**
  62. * Initialize the contents of the frame.
  63. */
  64.  
  65. public static void loginError(){ //Change login sucess indicator text on login error
  66. loginError.setText("Login Failed");
  67. }
  68.  
  69. public static void loginSuccess(){ //Change login sucess indicator text on success of login
  70. loginError.setText("Successful Login");
  71. }
  72.  
  73.  
  74. private void initialize() {
  75. frame = new JFrame();
  76. frame.setBounds(100, 100, 1000, 593);
  77. frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  78. frame.getContentPane().setLayout(null);
  79.  
  80. usernameField = new JTextField();
  81. usernameField.setBounds(117, 68, 308, 26);
  82. frame.getContentPane().add(usernameField);
  83. usernameField.setColumns(10);
  84.  
  85. passwordField = new JPasswordField();
  86. passwordField.setBounds(117, 106, 308, 26);
  87. frame.getContentPane().add(passwordField);
  88.  
  89. JLabel lblUsername = new JLabel("Username:");
  90. lblUsername.setBounds(12, 73, 93, 16);
  91. frame.getContentPane().add(lblUsername);
  92.  
  93. JLabel lblNewLabel = new JLabel("Password:");
  94. lblNewLabel.setBounds(12, 111, 93, 16);
  95. frame.getContentPane().add(lblNewLabel);
  96.  
  97. JButton btnLogin = new JButton("Login");
  98. btnLogin.setBounds(172, 144, 117, 29);
  99. btnLogin.addActionListener(new ActionListener() {
  100. public void actionPerformed(ActionEvent e) { //Log in to ECC
  101. MCBotMain.recieveCredentials(usernameField.getText(),passwordField.getText());
  102. }
  103. });
  104. frame.getContentPane().add(btnLogin);
  105.  
  106. JSeparator separator = new JSeparator();
  107. separator.setBounds(6, 175, 450, 12);
  108. frame.getContentPane().add(separator);
  109.  
  110. JLabel lblBotAccountLogin = new JLabel("Bot Account Login");
  111. lblBotAccountLogin.setBounds(154, 23, 135, 33);
  112. lblBotAccountLogin.setHorizontalAlignment(SwingConstants.CENTER);
  113. frame.getContentPane().add(lblBotAccountLogin);
  114.  
  115. commandBox = new JTextField();
  116. commandBox.setBounds(12, 524, 540, 26);
  117. frame.getContentPane().add(commandBox);
  118. commandBox.setColumns(10);
  119.  
  120. JButton btnEnter = new JButton("Enter");
  121. btnEnter.setBounds(555, 524, 117, 29);
  122. btnEnter.addActionListener(new ActionListener() {
  123. public void actionPerformed(ActionEvent e) { //Send command from console
  124.  
  125. MCBotMain bot = new MCBotMain();
  126. bot.sendMessage(commandBox.getText());
  127. commandBox.setText("");
  128.  
  129. }
  130. });
  131. frame.getContentPane().add(btnEnter);
  132.  
  133. scroll = new JScrollPane();
  134. scroll.setBounds(12, 199, 982, 313);
  135. frame.getContentPane().add(scroll);
  136.  
  137. chat = new JTextArea();
  138. chat.setLineWrap(true);
  139. chat.setEditable(false);
  140. scroll.setViewportView(chat);
  141.  
  142. loginError = new JLabel("");
  143. loginError.setBounds(301, 149, 179, 16);
  144. frame.getContentPane().add(loginError);
  145.  
  146.  
  147.  
  148.  
  149. DefaultCaret caret = (DefaultCaret) chat.getCaret();
  150. caret.setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE);
  151.  
  152.  
  153. }
  154.  
  155. public static void updateChat(String incomingMessage){ //Update chat box with incoming input
  156. chat.append("\n");
  157. chat.append(incomingMessage);
  158. }
  159. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement