Advertisement
Guest User

Untitled

a guest
Jan 19th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.18 KB | None | 0 0
  1. /**
  2. *Text genereted by Simple GUI Extension for BlueJ
  3. */
  4. import javax.swing.UIManager.LookAndFeelInfo;
  5. import java.awt.*;
  6. import java.awt.event.ActionEvent;
  7. import java.awt.event.ActionListener;
  8. import java.awt.event.KeyAdapter;
  9. import java.awt.event.KeyEvent;
  10. import java.awt.event.MouseAdapter;
  11. import java.awt.event.MouseListener;
  12. import java.awt.event.MouseEvent;
  13. import java.awt.Container;
  14.  
  15. import java.awt.event.MouseWheelEvent;
  16. import java.awt.event.MouseWheelListener;
  17. import javax.swing.border.Border;
  18. import javax.swing.*;
  19.  
  20. public class GUI_project extends JFrame
  21. implements ActionListener, MouseListener{
  22.  
  23. private JMenuBar menuBar;
  24. private JButton button1;
  25. private JTextArea textarea1;
  26. private JTextField textfield1;
  27. private JTextField textfield2;
  28.  
  29. //Constructor
  30. public GUI_project(){
  31.  
  32. this.setTitle("GUI_project");
  33. this.setSize(1085,721);
  34. //menu generate method
  35. generateMenu();
  36. this.setJMenuBar(menuBar);
  37.  
  38. //pane with null layout
  39. JPanel contentPane = new JPanel(null);
  40. contentPane.setPreferredSize(new Dimension(1085,721));
  41. contentPane.setBackground(new Color(192,192,192));
  42.  
  43. button1 = new JButton();
  44. button1.setBounds(545,529,351,150);
  45. button1.setBackground(new Color(214,217,223));
  46. button1.setForeground(new Color(0,0,0));
  47. button1.setEnabled(true);
  48. button1.setFont(new Font("sansserif",0,12));
  49. button1.setText("Button1");
  50. button1.setVisible(true);
  51. button1.addActionListener(this);
  52.  
  53. textarea1 = new JTextArea(16, 58);
  54. textarea1.setBounds(150,114,789,407);
  55.  
  56. textarea1.setEnabled(true);
  57. textarea1.setFont(new Font("sansserif",8,35));
  58. textarea1.setText("Hei, Philip! Hva kan jeg hjelpe med deg i dag?");
  59. textarea1.setBorder(BorderFactory.createBevelBorder(1));
  60. textarea1.setVisible(true);
  61.  
  62. textfield1 = new JTextField();
  63. textfield1.setBounds(177,525,337,160);
  64. textfield1.setBackground(new Color(255,255,255));
  65. textfield1.setForeground(new Color(0,0,0));
  66. textfield1.setEnabled(true);
  67. textfield1.setFont(new Font("sansserif",0,27));
  68. textfield1.setText("Skriv her..");
  69. textfield1.setVisible(true);
  70. textfield1.addMouseListener(this);
  71. addMouseListener(this);
  72.  
  73. textfield2 = new JTextField();
  74. textfield2.setBounds(267,50,523,58);
  75. textfield2.setBackground(new Color(255,255,255));
  76. textfield2.setForeground(new Color(0,0,0));
  77. textfield2.setEnabled(true);
  78. textfield2.setFont(new Font("sansserif",0,12));
  79. textfield2.setText(" CHATBOT GUI ");
  80. textfield2.setVisible(true);
  81. textfield2.setFont(textfield2.getFont().deriveFont(50.0f));
  82.  
  83. //adding components to contentPane panel
  84. contentPane.add(button1);
  85. contentPane.add(textarea1);
  86. contentPane.add(textfield1);
  87. contentPane.add(textfield2);
  88.  
  89. //adding panel to JFrame and seting of window position and close operation
  90. this.add(contentPane);
  91. this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  92. this.setLocationRelativeTo(null);
  93. this.pack();
  94. this.setVisible(true);
  95.  
  96. // scroll
  97. JScrollPane scroll = new JScrollPane (textarea1,
  98. JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
  99.  
  100. this.add(scroll);
  101. this.setVisible (true);
  102. scroll.setSize( 500, 500 );
  103. scroll.setBounds(150,114,789,407);
  104. }
  105.  
  106. public void actionPerformed(ActionEvent e) {
  107. String input = textfield1.getText();
  108.  
  109. textarea1.append("\n" + input);
  110. }
  111.  
  112. public void mouseEntered(MouseEvent e){
  113.  
  114. }
  115.  
  116. public void mouseClicked(MouseEvent e ){
  117. textfield1.setText("");
  118. }
  119.  
  120. public void mousePressed(MouseEvent e){
  121.  
  122. textfield1.setText("");}
  123.  
  124. public void mouseExited(MouseEvent e){
  125.  
  126. }
  127.  
  128. public void mouseReleased(MouseEvent e){
  129.  
  130. }
  131.  
  132. //method for generate menu
  133. public void generateMenu(){
  134. menuBar = new JMenuBar();
  135.  
  136. JMenu file = new JMenu("File");
  137. JMenu tools = new JMenu("Tools");
  138. JMenu help = new JMenu("Help");
  139.  
  140. JMenuItem open = new JMenuItem("Open ");
  141. JMenuItem save = new JMenuItem("Save ");
  142. JMenuItem exit = new JMenuItem("Exit ");
  143. JMenuItem preferences = new JMenuItem("Preferences ");
  144. JMenuItem about = new JMenuItem("About ");
  145.  
  146. file.add(open);
  147. file.add(save);
  148. file.addSeparator();
  149. file.add(exit);
  150. tools.add(preferences);
  151. help.add(about);
  152.  
  153. menuBar.add(file);
  154. menuBar.add(tools);
  155. menuBar.add(help);
  156. }
  157.  
  158. public static void main(String[] args){
  159. System.setProperty("swing.defaultlaf", "com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
  160. javax.swing.SwingUtilities.invokeLater(new Runnable() {
  161. public void run() {
  162. new GUI_project();
  163. }
  164. });
  165. }
  166.  
  167. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement