Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- *Text genereted by Simple GUI Extension for BlueJ
- */
- import javax.swing.UIManager.LookAndFeelInfo;
- import java.awt.*;
- import java.awt.event.ActionEvent;
- import java.awt.event.ActionListener;
- import java.awt.event.KeyAdapter;
- import java.awt.event.KeyEvent;
- import java.awt.event.MouseAdapter;
- import java.awt.event.MouseListener;
- import java.awt.event.MouseEvent;
- import java.awt.Container;
- import java.awt.event.MouseWheelEvent;
- import java.awt.event.MouseWheelListener;
- import javax.swing.border.Border;
- import javax.swing.*;
- public class GUI_project extends JFrame
- implements ActionListener, MouseListener{
- private JMenuBar menuBar;
- private JButton button1;
- private JTextArea textarea1;
- private JTextField textfield1;
- private JTextField textfield2;
- //Constructor
- public GUI_project(){
- this.setTitle("GUI_project");
- this.setSize(1085,721);
- //menu generate method
- generateMenu();
- this.setJMenuBar(menuBar);
- //pane with null layout
- JPanel contentPane = new JPanel(null);
- contentPane.setPreferredSize(new Dimension(1085,721));
- contentPane.setBackground(new Color(192,192,192));
- button1 = new JButton();
- button1.setBounds(545,529,351,150);
- button1.setBackground(new Color(214,217,223));
- button1.setForeground(new Color(0,0,0));
- button1.setEnabled(true);
- button1.setFont(new Font("sansserif",0,12));
- button1.setText("Button1");
- button1.setVisible(true);
- button1.addActionListener(this);
- textarea1 = new JTextArea(16, 58);
- textarea1.setBounds(150,114,789,407);
- textarea1.setEnabled(true);
- textarea1.setFont(new Font("sansserif",8,35));
- textarea1.setText("Hei, Philip! Hva kan jeg hjelpe med deg i dag?");
- textarea1.setBorder(BorderFactory.createBevelBorder(1));
- textarea1.setVisible(true);
- textfield1 = new JTextField();
- textfield1.setBounds(177,525,337,160);
- textfield1.setBackground(new Color(255,255,255));
- textfield1.setForeground(new Color(0,0,0));
- textfield1.setEnabled(true);
- textfield1.setFont(new Font("sansserif",0,27));
- textfield1.setText("Skriv her..");
- textfield1.setVisible(true);
- textfield1.addMouseListener(this);
- addMouseListener(this);
- textfield2 = new JTextField();
- textfield2.setBounds(267,50,523,58);
- textfield2.setBackground(new Color(255,255,255));
- textfield2.setForeground(new Color(0,0,0));
- textfield2.setEnabled(true);
- textfield2.setFont(new Font("sansserif",0,12));
- textfield2.setText(" CHATBOT GUI ");
- textfield2.setVisible(true);
- textfield2.setFont(textfield2.getFont().deriveFont(50.0f));
- //adding components to contentPane panel
- contentPane.add(button1);
- contentPane.add(textarea1);
- contentPane.add(textfield1);
- contentPane.add(textfield2);
- //adding panel to JFrame and seting of window position and close operation
- this.add(contentPane);
- this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
- this.setLocationRelativeTo(null);
- this.pack();
- this.setVisible(true);
- // scroll
- JScrollPane scroll = new JScrollPane (textarea1,
- JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
- this.add(scroll);
- this.setVisible (true);
- scroll.setSize( 500, 500 );
- scroll.setBounds(150,114,789,407);
- }
- public void actionPerformed(ActionEvent e) {
- String input = textfield1.getText();
- textarea1.append("\n" + input);
- }
- public void mouseEntered(MouseEvent e){
- }
- public void mouseClicked(MouseEvent e ){
- textfield1.setText("");
- }
- public void mousePressed(MouseEvent e){
- textfield1.setText("");}
- public void mouseExited(MouseEvent e){
- }
- public void mouseReleased(MouseEvent e){
- }
- //method for generate menu
- public void generateMenu(){
- menuBar = new JMenuBar();
- JMenu file = new JMenu("File");
- JMenu tools = new JMenu("Tools");
- JMenu help = new JMenu("Help");
- JMenuItem open = new JMenuItem("Open ");
- JMenuItem save = new JMenuItem("Save ");
- JMenuItem exit = new JMenuItem("Exit ");
- JMenuItem preferences = new JMenuItem("Preferences ");
- JMenuItem about = new JMenuItem("About ");
- file.add(open);
- file.add(save);
- file.addSeparator();
- file.add(exit);
- tools.add(preferences);
- help.add(about);
- menuBar.add(file);
- menuBar.add(tools);
- menuBar.add(help);
- }
- public static void main(String[] args){
- System.setProperty("swing.defaultlaf", "com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
- javax.swing.SwingUtilities.invokeLater(new Runnable() {
- public void run() {
- new GUI_project();
- }
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement