What will be the codes that I have to use?

Asked By 40 points N/A Posted on -
qa-featured

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

SHARE
Best Answer by Sheldon Ron
Best Answer
Best Answer
Answered By 0 points N/A #101965

What will be the codes that I have to use?

qa-featured

 

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.
 
Answered By 0 points N/A #195469

What will be the codes that I have to use?

qa-featured

 

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.

Related Questions