Someone help me add a GridBagLayout to my JApplet here is the code i have
but that didnt work ?Code:import java.applet.*; import java.awt.*; import java.awt.event.*; import javax.swing.*; public class widget extends JApplet implements ActionListener { JRadioButton optBlue = new JRadioButton("Blue"); JRadioButton optRed = new JRadioButton("Red"); JRadioButton optYellow = new JRadioButton("Yellow"); JLabel lblTitle = new JLabel(" Widgets "); JLabel lblWidgetColor = new JLabel(" Widget Color: "); JLabel lblQuantity = new JLabel(" Quantity "); JLabel lblName = new JLabel(" Name: "); JLabel lblAddress = new JLabel(" Address: "); JLabel lblCreditCard = new JLabel(" Credit Card: "); JTextField txtName = new JTextField(" John Smith "); JTextField txtAddress = new JTextField(" "); JTextField txtQuantity = new JTextField("0"); JTextArea txaCurrentPurchase = new JTextArea(10,50); JTextArea txaPurchase = new JTextArea(10,50); JCheckBox chkEngrave = new JCheckBox(" Engrave"); JButton btnAddToShoppingCart = new JButton(" Add to Shopping Cart "); JButton btnPurchase = new JButton(" Purchase "); JPanel pnlApplet = new JPanel();//Panel for Applet JPanel pnlMain = new JPanel(); //Panel for Content Font fntMain = new Font("Arial",Font.BOLD,12); public void init() { pnlMain.add(DesignLayout()); pnlApplet.add(pnlMain); } public void actionPerformed(ActionEvent action) { } public void DesignLayout() { // Sets the Layout Mangers propertys GridBagLayout gridbag = new GridBagLayout(); GridBagConstraints constraints = new GridBagConstraints(); setLayout(gridbag); constraints.insets = new Insets(5,2,5,2); constraints.fill = GridBagConstraints.NONE; //Adds Label(lblTitle) to 0,0 constraints.gridx = 0; constraints.gridy = 0; constraints.anchor = GridBagConstraints.EAST; gridbag.setConstraints(lblTitle,constraints); lblTitle.setForeground(Color.orange); add(lblTitle); } }




Reply With Quote