//Improved Gui for the same RUN window of previous problem using GridBagLayout
import java.awt.event.*;
import javax.swing.*;
class RunGridBag extends JFrame{
private JLabel lblimage,lblopen,lblcomment1,lblcomment2;
private JButton btnok,btncancel,btnbrowse;
private JComboBox commandList;
private GridBagConstraints c =new GridBagConstraints();
private GridBagLayout gbl =new GridBagLayout();
RunGridBag(String title){
super(title);
setLayout(gbl);
setSize(400,200);
setResizable(false);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
addComponent();
setVisible(true);
}
void addComponent(){
c.fill = GridBagConstraints.BOTH;
c.gridheight=2;
ImageIcon img = new ImageIcon("logo.png");
lblimage = new JLabel(img);
gbl.setConstraints(lblimage,c);
add(lblimage);
c.gridheight=1;
lblcomment1 = new JLabel("Type the name of a program,folder,document,or Internet");
lblcomment1.setOpaque(true);
lblcomment1.setBackground(Color.WHITE);
c.gridwidth=GridBagConstraints.REMAINDER;
gbl.setConstraints(lblcomment1,c);
add(lblcomment1);
lblcomment2 = new JLabel("resource, and Windows will open it for you");
lblcomment2.setOpaque(true);
lblcomment2.setBackground(Color.WHITE);
gbl.setConstraints(lblcomment2,c);
add(lblcomment2);
c.gridwidth = GridBagConstraints.LINE_START;
lblopen = new JLabel("Open:");
lblopen.setOpaque(true);
lblopen.setBackground(Color.WHITE);
gbl.setConstraints(lblopen,c);
add(lblopen);
String[] commandStrings = { "calc","winword","control panel","cmd"};
commandList = new JComboBox(commandStrings);
commandList.setEditable(true);
c.gridwidth = GridBagConstraints.REMAINDER;
commandList.setBackground(Color.WHITE);
gbl.setConstraints(commandList,c);
add(commandList);
c.weightx=1;
c.insets = new Insets(20,100,20,5);
c.gridwidth = GridBagConstraints.FIRST_LINE_END;
btnok = new JButton("OK");
gbl.setConstraints(btnok,c);
add(btnok);
c.insets = new Insets(20,5,20,5);
btncancel = new JButton("CANCEL");
gbl.setConstraints(btncancel,c);
add(btncancel);
btnbrowse = new JButton("Browse..");
gbl.setConstraints(btnbrowse,c);
add(btnbrowse);
}
public static void main (String[] args) {
RunGridBag r = new RunGridBag("Run");
r.pack();
}
}
No comments:
Post a Comment