gpt4 book ai didi

java jdbc 和 jframe

转载 作者:行者123 更新时间:2023-12-01 13:12:34 25 4
gpt4 key购买 nike

当我执行应用程序时,我得到“构建成功”,但屏幕上未显示jframe。该应用程序是关于从 oracle 数据库检索数据并从数据库中查找特定的人(记录)。 jframe 可能包含人员详细信息例如名字、姓氏...等。我可以浏览数据库中的记录。

class Addressbks extends javax.swing.JFrame
{
private JButton browseButton;

private JLabel emailLabel;
private JTextField emailTextField;
private JLabel firstNameLabel;
private JTextField firstNameTextField;
private JLabel lastNameLabel;
private JTextField lastNameTextField;
private JLabel idLabel;
private JTextField idTextField;
private JLabel phoneLabel;
private JTextField phoneTextField;
private JTextField indexTextField;


private JPanel navigatePanel;
private JPanel displayPanel;
private JPanel queryPanel;

private JButton previousButton;
private JButton nextButton;

private JLabel ofLabel;
private JTextField maxTextField;
private JTextField queryTextField;

private Person currentEntry;
private PersonQueries personQueries;
private List<Person> results;
private int numberOfEntries = 0;
private int currentEntryIndex;
private JLabel queryLabel;

private JButton queryButton;
private JButton insertButton;


/**
* Creates new form Address book
*/
public Addressbks() {
super("The Addressbook");
initComponents();

setLayout(new FlowLayout(FlowLayout.CENTER,10,10));


personQueries = new PersonQueries();

navigatePanel = new JPanel();
previousButton = new JButton();
indexTextField = new JTextField(2);
ofLabel = new JLabel();
maxTextField = new JTextField(2);
nextButton = new JButton();

displayPanel = new JPanel();
idLabel = new JLabel();
idTextField = new JTextField(10);
firstNameLabel = new JLabel();
firstNameTextField = new JTextField(10);
lastNameLabel = new JLabel();
lastNameTextField = new JTextField(10);
emailLabel = new JLabel();
emailTextField = new JTextField(10);
phoneLabel = new JLabel();
phoneTextField = new JTextField(10);



queryPanel = new JPanel();
queryLabel = new JLabel();
queryTextField =new JTextField(10);
queryButton= new JButton();
browseButton = new JButton();
insertButton = new JButton();



navigatePanel.setLayout(new BoxLayout(navigatePanel,BoxLayout.X_AXIS));
previousButton.setText("Previous");

previousButton.setEnabled(false);

previousButton.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e)
{
previousButtonActionPerformed(e);
}
});
navigatePanel.add(previousButton);
navigatePanel.add(Box.createHorizontalStrut(10));

indexTextField.setHorizontalAlignment(JTextField.CENTER);

indexTextField.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e)
{
indexTextFieldActionPerformed(e);
}
});

navigatePanel.add(indexTextField);
navigatePanel.add(Box.createHorizontalStrut(10));

ofLabel.setText("of");
navigatePanel.add(ofLabel);
navigatePanel.add(Box.createHorizontalStrut(10));

maxTextField.setHorizontalAlignment(JTextField.CENTER);
maxTextField.setEditable(false);
navigatePanel.add(maxTextField);
navigatePanel.add(Box.createHorizontalStrut(10));

nextButton.setText("Next");
nextButton.setEnabled(false);
nextButton.addActionListener(new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e)
{
nextButtonActionPerformed(e);
}
});
navigatePanel.add(nextButton);
add(navigatePanel);

displayPanel.setLayout(new GridLayout(5,2,4,4));

idLabel.setText("Address ID");
displayPanel.add(idLabel);


idTextField.setEditable(false);
displayPanel.add(idTextField);


firstNameLabel.setText("First Name :");
displayPanel.add(firstNameLabel);
displayPanel.add(firstNameTextField);

lastNameLabel.setText("Last Name :");
displayPanel.add(lastNameLabel);
displayPanel.add(lastNameTextField);

emailLabel.setText("Email :");
displayPanel.add(emailLabel);
displayPanel.add(emailTextField);

phoneLabel.setText("Phone Number :");
displayPanel.add(phoneLabel);
displayPanel.add(phoneTextField);
add(displayPanel);

queryPanel.setLayout(new BoxLayout(queryPanel,BoxLayout.X_AXIS));
queryPanel.setBorder(BorderFactory.createTitledBorder("Find an entry by lastname"));

queryLabel.setText("Last Name");
queryPanel.add(Box.createHorizontalStrut(5));

queryPanel.add(queryLabel);
queryPanel.add(Box.createHorizontalStrut(10));
queryPanel.add(queryTextField);
queryPanel.add(Box.createHorizontalStrut(10));

queryButton.setText("Find");
queryButton.addActionListener(new ActionListener()
{

@Override
public void actionPerformed(ActionEvent e)
{
queryButtonActionPerformed(e);
}
});
queryPanel.add(queryButton);
queryPanel.add(Box.createHorizontalStrut(5));
add(queryPanel);

browseButton.setText("Browse All Entries");
browseButton.addActionListener(new ActionListener()
{

@Override
public void actionPerformed(ActionEvent e)
{
browseButtonActionPerformed(e);
}
});

add(browseButton);

insertButton.setText("Insert New Entry");
insertButton.addActionListener(new ActionListener()
{

@Override
public void actionPerformed(ActionEvent e)
{
insertButtonActionPerformed(e);
}
});
add(insertButton);

/* addWindowListener (new WindowAdapter()
{
@Override
public void windowClosing(WindowEvent e)
{
personQueries.close();
//System.exit(0);
}
});*/

// setSize(400,400);
// setResizable(false);
// setLocationRelativeTo(null);
// setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
// setVisible(true);

}
public class Addressbook
{
/**
* @param args the command line arguments
*/

public static void main(String args[]) throws InterruptedException
{

try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException | javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(Addressbook.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//</editor-fold>

/* Create and display the form */
/*context: a.setVisible(true) still the jframe is not displayed */

java.awt.EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
JFrame a = new Addressbks();
a.setVisible(true);

}
});
}
}

最佳答案

您尚未设置 a JFrame 的大小,请尝试将 setSize() 方法添加到您的代码中,如下所示:

JFrame a = new Addressbks();
a.setSize(400, 400);
a.setVisible(true);

或者您可以使用pack(),它会调整框架的大小,以便其所有内容都等于或高于其首选大小。

JFrame a = new Addressbks();
a.pack();
a.setVisible(true);

关于java jdbc 和 jframe,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22741348/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com