Example of a gui with different features.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 | /******************************************************* * MYCPLUS Sample Code - https://www.mycplus.com * * * * This code is made available as a service to our * * visitors and is provided strictly for the * * purpose of illustration. * * * * Please direct all inquiries to saqib at mycplus.com * *******************************************************/ import javax.swing.*; import java.awt.*; import java.io.*; import java.awt.event.*; class GUI extends JFrame implements ActionListener { JComboBox help = new JComboBox(); JLabel txtlabel = new JLabel("Coded by system error, http://system-error.weebly.com"); JButton button1 = new JButton("First button"); JButton button2 = new JButton("Second button"); JButton button3 = new JButton("Third button"); JTextArea output = new JTextArea("output results..., you can also write some text in here \n and look at the 1337 colors", 14, 45); //text area public GUI() { super("System error's program "); setSize(600, 500); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); //create window setVisible(true); // Container contentArea = getContentPane(); contentArea.setBackground(Color.gray); //create conent container // FlowLayout flowManager = new FlowLayout(); contentArea.setLayout(flowManager); //creae layout manager // JComboBox help = new JComboBox(); help.setForeground(Color.black); help.setBackground(Color.lightGray); setContentPane(contentArea); help.addItem("Help"); help.addItem(""); help.addItem("This is where i'll explain"); //combo box help help.addItem("What the program is and exactly"); help.addItem("how to use it, I haven't got"); help.addItem("a clue what I want to do yet though."); contentArea.add(help); // txtlabel.setBackground(Color.darkGray); contentArea.add(txtlabel); //text label setContentPane(contentArea); // output.setForeground(Color.green); output.setBackground(Color.black); contentArea.add(output); setContentPane(contentArea); // JScrollPane scroller = new JScrollPane(output, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); //scroll pane scroller.setForeground(Color.darkGray); contentArea.add(scroller); setContentPane(contentArea); // button1.addActionListener(this); button1.setBackground(Color.lightGray); //buttons button1.setForeground(Color.black); contentArea.add(button1); setContentPane(contentArea); button2.addActionListener(this); button2.setBackground(Color.lightGray); button2.setForeground(Color.black); contentArea.add(button2); setContentPane(contentArea); button3.addActionListener(this); button3.setBackground(Color.lightGray); button3.setForeground(Color.black); contentArea.add(button3); setContentPane(contentArea); // txtlabel2.setBackground(Color.darkGray); contentArea.add(txtlabel2); //text label setContentPane(contentArea); } public void actionPerformed (ActionEvent event) { if(event.getSource() == button1) output.setText("You pressed button1, why? it has no functions yet!"); if(event.getSource() == button2) output.setText("You pressed button2, you must be really fucking bored"); if(event.getSource() == button3) output.setText("You pressed button3, man... can't you see that the 1st and 2nd buttons \n dont have any functions! why do think the 3rd one will?.. \n ohh third time lucky you was probably thinking"); } public static void main (String [] args) {GUI eg = new GUI();} } |