小编Saj*_*jad的帖子

如何通过一个语句描述数据库中的所有表?

是否有可以描述数据库中所有表的语句?

像这样的东西:

describe * from myDB;
Run Code Online (Sandbox Code Playgroud)

mysql

36
推荐指数
4
解决办法
6万
查看次数

isEmpty()和零长度之间的差异

这两种方法有什么区别?

public boolean nameControl(String str) 
{
    if (str.trim().isEmpty()) return false;
    if (str.trim().length() == 0) return false;
    return true;
}
Run Code Online (Sandbox Code Playgroud)

我需要找出str至少应该有一个角色.

java string

8
推荐指数
1
解决办法
7935
查看次数

最后关闭连接和声明

哪个更适合finally块:

finally {
        try {
            con.close();
            stat.close();
        } catch (SQLException sqlee) {
            sqlee.printStackTrace();
        }
    }
Run Code Online (Sandbox Code Playgroud)

要么:

finally {
        try {
            if (con != null) {
                con.close();
            }
            if (stat != null) {
                stat.close();
            }
        } catch (SQLException sqlee) {
            sqlee.printStackTrace();
        }
    }
Run Code Online (Sandbox Code Playgroud)

java connection finally jdbc try-catch

7
推荐指数
3
解决办法
3万
查看次数

在接口中使用set/get方法

我是Java新手(整整一年!)

我的问题是我如何在接口中编写set/get方法和静态字段,并在另一个类中实现它.

我的代码是这样的:(简短!)

public interface myInterface{
int number=0;

public int setNumber(int num);{

}
}

// my class

public void myClass extends JFrame implements myInterface{

 ...

public int setNumber(int num){
   number=num;                      // Error!   Why? What I do?

 }
}
Run Code Online (Sandbox Code Playgroud)

在语句中number=num它有错误,但它在setName方法中没有错误!

java interface

4
推荐指数
2
解决办法
3万
查看次数

写入文件而不删除旧数据

可能重复: java追加到文件 如何将数据附加到文件?

我想在java中编写一个文件而不清除(删除)该文件中的旧数据!

我运行此代码,看到每次运行后都清理.txt文件中的所有旧数据!

我的代码在这里:

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

public class WriteToFileExample {

public static void main(String[] args) {
    try {

        String content = "This is the content to write into file";

        File file = new File("/users/mkyong/filename.txt");

        // if file doesnt exists, then create it
        if (!file.exists()) {
            file.createNewFile();
        }

        FileWriter fw = new FileWriter(file.getAbsoluteFile());
        BufferedWriter bw = new BufferedWriter(fw);
        bw.write(content);
        bw.close();

        System.out.println("Done");

    } catch (IOException e) {
        e.printStackTrace();
    }
}
}
Run Code Online (Sandbox Code Playgroud)

java file-io

4
推荐指数
1
解决办法
3万
查看次数

Jtable更新选定的行

我有一个jtable有一个编辑按钮,当我选择一行并单击编辑按钮和编辑字段,然后单击保存按钮,该行不更新,我必须刷新我的表以更改该行!

我的代码:

        if (e.getSource() == editButton) {
        selectedRow = uTable.getSelectedRow();
        if (selectedRow >= 0) {
            editUser(selectedRow);
        } else {
            JOptionPane.showMessageDialog(null, "Select a row");
        }
    }

    public void editUser(int row) {
    UserInformation userInf = userModel.getSelectedMember(row);
    NewUserFrame_Edit edit = new NewUserFrame_Edit(userInf, row);
}

...
Run Code Online (Sandbox Code Playgroud)

我的NewUserFrame_Edit类:

public class NewUserFrame_Edit extends javax.swing.JFrame {

private AllUser userModel;
private int selectedrow;
private String gender;

public NewUserFrame_Edit(AllUser userModel,UserInformation userinf, int row) {
...
this.userModel = userModel;
    jTextField1.setText(userinf.getFname().toString().trim());
    jTextField2.setText(userinf.getLname().toString().trim());

    if (userinf.getGender().equals("Male")) {
        jRadioButton1.setSelected(true);
    } else {
        jRadioButton2.setSelected(true);
    } …
Run Code Online (Sandbox Code Playgroud)

java swing jtable

4
推荐指数
2
解决办法
3万
查看次数

JFrame着色应该喜欢这张照片

我的问题有点奇怪.

我希望我创建的表单(使用JFrame)着色应该像这样的图片:

在此输入图像描述

我应该使用特殊的外观吗?

java swing color-management jframe

4
推荐指数
1
解决办法
2920
查看次数

Jtable行删除

我正在用java创建一个没有数据库的库系统程序.(直接用文件).

我在jtable中删除一行(从文件中删除)也有一个奇怪的问题.

有时当我在表格中选择一行并单击删除按钮时,更多的一行已被删除!

也是大多数时候它正常工作!!

我的代码:

public final class UserPage extends JFrame implements ActionListener {

    private AllUser userModel;
    private JTable uTable;
    JButton deleteUser;
    int selectedRow;

    public UserPage() {
        titleUserCount();
        userModel = new AllUser();
        uTable = new JTable(userModel);
        add(new JScrollPane(uTable), BorderLayout.CENTER);
        add(buttonPanels(), BorderLayout.PAGE_START);
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setSize(800, 600);
        this.setLocation(300, 60);
        this.setResizable(false);
    }   

    public final JPanel buttonPanels() {
        JPanel buttonsPanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
        deleteUser = new JButton("Delete User");

        deleteUser.addActionListener(this);
        buttonsPanel.add(deleteUser);

        return buttonsPanel;
    }   

    public void titleUserCount() {
        AllUser userCount = new AllUser();
        UserPage.this.setTitle("All User …
Run Code Online (Sandbox Code Playgroud)

java swing jtable

3
推荐指数
1
解决办法
7204
查看次数

继承中的覆盖方法

我的代码:

public class PrivateOverride {

private void f() {
    System.out.println("private f()");
}

public static void main(String[] args) {
    PrivateOverride po = new derived();
    po.f();
   }
}

class derived extends PrivateOverride {

public void f() {
    System.out.println("public f()");
    }
}
Run Code Online (Sandbox Code Playgroud)

输出: private f()

为什么?

java inheritance overriding

3
推荐指数
1
解决办法
71
查看次数

在keyBinding中聚焦导航

在我的表单中,当我按下ENTER键盘上的按钮时,okAction()应调用该方法(并完美调用).

我的问题是焦点状态,当我填写文本字段然后按下ENTER按钮时,okAction()没有调用,因为焦点在第二个文本字段(不在面板上).

怎么解决这个问题?

public class T3 extends JFrame implements ActionListener {

JButton cancelBtn, okBtn;
JLabel fNameLbl, lNameLbl, tempBtn;
JTextField fNameTf, lNameTf;

public T3() {
    add(createForm(), BorderLayout.NORTH);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setSize(400, 500);
    setVisible(true);
}

public static void main(String[] args) {
    SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
            new T3();
        }
    });
}

public JPanel createForm() {
    JPanel panel = new JPanel();
    panel.getInputMap().put(KeyStroke.getKeyStroke("ENTER"), "Button");
    panel.getActionMap().put("Button", new AbstractAction() {
        @Override
        public void actionPerformed(ActionEvent e) {
            okAction(); …
Run Code Online (Sandbox Code Playgroud)

java swing key-bindings focusmanager

2
推荐指数
1
解决办法
189
查看次数