A simple GUI code
by , 12-18-2011 at 01:25 PM (1453 Views)
Java Code:package myPackage; import java.awt.Color; import java.awt.FlowLayout; import javax.swing.*; @SuppressWarnings("serial") public class SamsLearning extends JFrame { public SamsLearning() { super(); this.setTitle("My Title"); this.setLookAndFeel(); this.setSize(500,500); MyButtonClass myButton = new MyButtonClass("Play"); MyButtonClass myButton2 = new MyButtonClass("Stop"); MyJLabelClass myLabel = new MyJLabelClass(); myLabel.setText("This is a label!"); JLabel heyo = new JLabel("heyp", JLabel.LEFT); JCheckBox jumboSize = new JCheckBox("Jumbo Size",false); JCheckBox mercedes = new JCheckBox("Mercedes"); JCheckBox bmw = new JCheckBox("Bmw"); JCheckBox audi = new JCheckBox("Audi"); ButtonGroup carbrands = new ButtonGroup(); carbrands.add(mercedes); carbrands.add(bmw); carbrands.add(audi); FlowLayout flo = new FlowLayout(); this.setLayout(flo); JPanel topRow = new JPanel(); topRow.setName("No name"); this.add(topRow); topRow.add(mercedes); topRow.add(bmw); topRow.add(audi); JTextArea comments = new JTextArea("Hello\nHow are you?",8,40); this.add(comments); this.add(myButton); this.add(myButton2); this.add(myLabel); this.add(heyo); this.add(jumboSize); this.setVisible(true); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); }//end constructor private void setLookAndFeel() { try { UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel" ); } catch(Exception exc) { System.out.println("Somethinw went wrong. Using the default LookAndFeel.."); } } }//end class SamsLearningJava Code:package myPackage; public class SamsLearningTest { public static void main(String[] args) { SamsLearning myLearning = new SamsLearning(); } }![]()










Email Blog Entry
PDF to TIFF Conversion & Control...
05-24-2013, 11:39 AM in Java Software