简体   繁体   English

帮助Java程序(Swing +数据库)

[英]Help with Java program (Swing + database)

Could somebody give me a suggestion on how to simply and effectively make GUI representation of directories which are contained inside the database. 有人可以给我一个关于如何简单有效地对数据库中包含的目录进行GUI表示的建议。 Now, getting information using SQL queries is one thing. 现在,使用SQL查询获取信息是一回事。 I can do that. 我能做到。 In fact using separate small examples I can put a file inside the database along with his information and I can get the file out of the database. 事实上,使用单独的小例子我可以将文件放在数据库中以及他的信息,我可以从数据库中获取文件。 The thing is I was just doing this without GUI, just to test does it work. 问题是我只是在没有GUI的情况下这样做,只是为了测试它是否有效。

Now I need a GUI of this and I really don't know where to start. 现在我需要一个GUI,我真的不知道从哪里开始。 DO I use JTable, JList or something third? 我是使用JTable,JList还是第三种? Also, I think I need an multidimensional array because I have, for example, id of a file, name_of_file and size. 另外,我认为我需要一个多维数组,因为我有一个文件的id,name_of_file和size。

So I need different types to put them in: int, String and int. 所以我需要不同的类型来放入它们:int,String和int。 Also, I need to obviously hide the id of a file from the user yet keep it at the same time in order to be able to reference it. 此外,我需要显然隐藏用户的文件ID,但同时保留它以便能够引用它。

How do I hide it in a GUI component? 如何将其隐藏在GUI组件中?

So, let's say that I have a database table for files with these columns: id, name, size, binary_of_file. 所以,假设我有一个包含这些列的文件的数据库表:id,name,size,binary_of_file。

My real table has a bit more of columns like, id of a parent directory, id of a owner, etc. but for now this is not important. 我的真实表有更多的列,如父目录的id,所有者的id等,但是现在这并不重要。

So, I tell database to give me all info about the file (except it's binary because I just want to list the files): 所以,我告诉数据库给我关于该文件的所有信息(除了它的二进制文件,因为我只想列出文件):

...
ResultSet rs = statementObject.executeQuery("SELECT id, name, size FROM Files;");
while(rs.next()){
    //Where do I store the values in? Which GUI component and how?
...

I guess I need an JPanel that will contain this component that will show my files from the database. 我想我需要一个包含这个组件的JPanel,它将从数据库中显示我的文件。 What component? 什么组件? Please help! 请帮忙!

It sounds like you want to use a JTable, it has a TableModel interface that you can implement to adapt to your resultset. 听起来你想要使用JTable,它有一个TableModel接口,你可以实现它来适应你的结果集。


Also follow the link at the top of the docs. 另请点击文档顶部的链接。 to Creating a Table Model . 创建表模型

Perhaps a combined JList / JTable component would fit this need. 也许组合的JList / JTable组件JList这种需求。

That is a screen shot of the GUI of FileBro . 这是FileBro的GUI的屏幕截图。

My idea is that the JTree on the left would represent the 'directories' and table (names) of the DB. 我的想法是左边的JTree代表DB的'目录'和表(名称)。 The JTable on the right would contain the data of the selected table. 右侧的JTable将包含所选表的数据。 Change the Locate Open Edit Print buttons for Create Update Delete and the panel below that to show details of records, and it would be the start of a DB CRUD component. 更改“ Create Update Delete ”的“ Locate Open Edit Print按钮和下面的面板以显示记录的详细信息,它将是DB CRUD组件的开头。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM