Hi friend,
I'm working on my first java project and I want to add label,textbox,checkbox,combobox and command button on it. to look it better but I don't know how to code them. May you help me with this?
Thanks
What will be the codes that I have to use?
Â
import javax.swing.*;
Put the code below in your main project.
Â
Panel panel;
JCheckBox  chkbox;
Jlabel lblmain;
JButton cmdSegment;
JCombo combo;
Â
frame = new JFrame("Display image");
panel=new Panel();
   frame.getContentPane().add(panel);
   frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
   frame.setSize(500, 1000);
   frame.setVisible(true);
   lblmain = new JLabel();
panel.add(lblmain);
   cmdSegment= new javax.swing.JButton();
   cmdSegment.setText("Segment");
   cmdSegment.setVisible(true);
   panel.add(cmdSegment);
   chkbox= new  javax.swing.JCheckBox  (); Â
panel.add(chkbox);
   txtMsg=new javax.swing.JTextArea();
   txtMsg.setMaximumSize(new java.awt.Dimension(200, 200));
   txtMsg.setMinimumSize(new java.awt.Dimension(200, 200));
   panel.add(txtMsg);
 combo= new  javax.swing.JCombo  (); Â
 panel.add(combo);
   cmdSegment.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
        try{
          cmdSegmentOnClick(evt);
        }catch(Exception e){
          txtMsg.setText(txtMsg.getText()+"n"+e.getMessage()+e.getStackTrace());
        }
      }
    });
    delimiter.addChangeListener(new javax.swing.event.ChangeListener() {
      public void stateChanged(javax.swing.event.ChangeEvent evt) {
        try{
          delimiterChange(evt);
        }catch(Exception e){
          txtMsg.setText(txtMsg.getText()+"n"+e.getMessage()+e.getStackTrace());
        }
      }
    });
   txtMsg.setText("Output Messages………………………………………………………………………………………………………………");
An explanation,
All you need to do is to create a frame then insert panel to the frame. then you can create objects of command, check, textbox and others to add to the panel. the order on which you add the controls give the display in the frame window.
Â
The program creates label,textbox,checkbox,combobox and command button to a panel which is in a frame.
Thanks. Please provide a feedback.
Â
What will be the codes that I have to use?
Â
Hi Jacobo Martin,
Â
There is no need for you to write code for adding label,text box or check box or anything GUI related in Java. You can use Netbeans IDE instead. It provides you a neat and simple UI where you can drag and drop whatever features you want. Below is the link which provides you with a tutorial for how to create a GUI in java using Netbeans IDE.
Â
Â
Hope it helps.