Quote
I have a few panels on the form to hold my containers, but what I don't understand is why is the second panel filling the form? Also how come my text boxes are so big? Does it have to do with the BoxLayout and BorderLayout?
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
/**
*
* @author James
*/
class form extends JFrame implements ActionListener {
// these go in a panel together
JPanel pnlName = new JPanel();
JLabel lblName = new JLabel("Enter name: ");
JTextField txtName = new JTextField(5);
// these go in a panel together
JPanel pnlCost = new JPanel();
JLabel lblCost = new JLabel(" enter cost: ");
JTextField txtCost = new JTextField(6);
// these go in a panel together
JPanel pnlComm = new JPanel();
JLabel lblComm = new JLabel(" commission: ");
JTextField txtComm = new JTextField(6);
JPanel pnlButtons = new JPanel();
JButton btnUpdate = new JButton("Update Name");
form() {
setTitle("Commission");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
add();
btnUpdate.addActionListener(this);
}
void add() {
setLayout(new FlowLayout());
pnlName.setLayout(new BoxLayout(pnlName, BoxLayout.Y_AXIS));
pnlName.add(lblName);
pnlName.add(txtName);
pnlCost.setLayout(new BoxLayout(pnlCost, BoxLayout.Y_AXIS));
pnlCost.add(lblCost);
pnlCost.add(txtCost);
pnlComm.setLayout(new BoxLayout(pnlComm, BoxLayout.Y_AXIS));
pnlComm.add(lblComm);
pnlComm.add(txtComm);
pnlButtons.setLayout(new BoxLayout(pnlButtons, BoxLayout.Y_AXIS));
pnlButtons.add(btnUpdate);
pnlCost.setVisible(false);
pnlComm.setVisible(false);
setLayout(new BorderLayout());
add(pnlName, BorderLayout.NORTH);
add(pnlCost, BorderLayout.CENTER);
add(pnlComm, BorderLayout.SOUTH);
add(pnlButtons, BorderLayout.SOUTH);
}
public void actionPerformed(ActionEvent evt) {
String sCost;
sCost = txtName.getText() + lblCost.getText();
lblCost.setText(sCost);
pnlCost.setVisible(true);
pnlComm.setVisible(true);
pnlButtons.setVisible(false);
}
}
public class e1d {
public static void main(String[] args) {
form e1d = new form();
e1d.setVisible(true);
e1d.setSize(300, 200);
}
}


Ask A New Question
Reply






MultiQuote








|