I need to write a code that generates library number and resize the JButton to put it to the bottom of the frame.
我需要编写一个代码,从1001生成库号,每个后续号码应该更大。生成库编号并在文本字段中显示后,按钮文本应更改为“确认”。
import java.awt.*;
import javax.swing.*;
import java.awt.event.*;
public class HW4GUI extends JFrame implements ActionListener
{
private JButton jbtAction;
private JTextField jtfFName;
private JTextField jtfLName;
private JTextField jtfLibNo;
private int nextLibNo;
private JPanel textPanel;
public HW4GUI()
{
setTitle("HW4 GUI");
makeFrame();
showFrame();
}
public void actionPerformed(ActionEvent e)
{
I need to write a code that generates library number from 1001 and each subsequent number should be one greater. Once the library number has been generated and shown in the text field, the button text should change to ‘Confirm’.
}
public void makeFrame() Make frame method
{
setLayout( new GridLayout(4,0) );
jtfFName = new JTextField( 15 ) ;
JLabel aLabel = new JLabel("First Name: ");
jtfFName.setActionCommand("First Name");
jtfFName.setHorizontalAlignment(aLabel.RIGHT);
jtfLName = new JTextField( 15 ) ;
JLabel aLabel1 = new JLabel("Last Name: ");
jtfLName.setActionCommand("Last Name");
jtfLName.setHorizontalAlignment(aLabel1.RIGHT);
jtfLibNo = new JTextField( 10 ) ;
JLabel aLabel2 = new JLabel("Library Number: ");
jtfLibNo.setActionCommand("Library Number");
jtfLibNo.setEditable(false);
jtfLibNo.setHorizontalAlignment(aLabel2.RIGHT);
add(aLabel);
add(jtfFName);
add(aLabel1);
add(jtfLName);
add(aLabel2);
add(jtfLibNo);
JPanel textPanel = new JPanel();
jbtAction = new JButton("Add Borrower");
jbtAction.setLayout(new BoxLayout(jbtAction, BoxLayout.PAGE_AXIS));
add(jbtAction); I need to resize this button
jtfFName.addActionListener( this );
jtfLName.addActionListener( this );
jtfLibNo.addActionListener( this );
jbtAction.addActionListener( this );
}
public void showFrame()
{
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setLocationRelativeTo(null);
setSize(400,200);
setVisible(true);
}
}