问答文章1 问答文章501 问答文章1001 问答文章1501 问答文章2001 问答文章2501 问答文章3001 问答文章3501 问答文章4001 问答文章4501 问答文章5001 问答文章5501 问答文章6001 问答文章6501 问答文章7001 问答文章7501 问答文章8001 问答文章8501 问答文章9001 问答文章9501

...内容显示在当前的界面上面,而不是新创建一个窗口来显示?

发布网友 发布时间:2024-10-02 22:23

我来回答

4个回答

热心网友 时间:2024-10-19 15:37

package com.gxa.Export;

import java.awt.event.*;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

import com.gxa.Main.Main;
import com.gxa.Pub.*;
import javax.swing.*;
import javax.swing.table.DefaultTableModel;

public class ExportSelectPanel implements ActionListener{
JPanel pSelect;
JComboBox cb;
JTextField tfd;
JLabel lb;
JButton btn1,btn2;

public void actionPerformed(ActionEvent e) {
Object btn = e.getSource();
PreparedStatement prep = null;
ResultSet rs;
if(btn==cb && cb.getSelectedItem().equals("入库日期")){
pSelect.add(lb);
}
if(btn==btn1){
Object cbName = cb.getSelectedItem();
String[] col = { "iExportId", "cEmployeeId", "dShipmentDate",
"cGoodId", "mPrice", "iAmount", "cStorageCode" };
DefaultTableModel mm = new DefaultTableModel(col, 0); // 定义一个表的模板
String str = tfd.getText();

try{
Connection conn = Conn.getCon().con;
if(tfd.getText().length()==0){
prep = conn.prepareStatement("select * from Export");
}
else if(cbName.equals("入库单号")){
prep = conn.prepareStatement("select * from Export where iExportId= ?");
prep.setString(1,str);
if(str.equals("")){
JOptionPane.showMessageDialog(ExportMainPanel.getExportMainPanel(), "请输入入库单号!");
return;
}else if(!str.matches("^\\d+$")){
JOptionPane.showMessageDialog(ExportMainPanel.getExportMainPanel(), "入库单号只能为数字!");
return;
}
}
else if(cbName.equals("经手人ID")){
prep = conn.prepareStatement("select * from Export where cEmployeeId= ?");
prep.setString(1,str);
if(str.equals("")){
JOptionPane.showMessageDialog(ExportMainPanel.getExportMainPanel(), "请输入经手人!");
return;
}else if(!str.matches("^\\d+$")){
JOptionPane.showMessageDialog(ExportMainPanel.getExportMainPanel(), "经手人只能为数字!");
return;
}
}
else if(cbName.equals("入库日期")){
prep = conn.prepareStatement("select * from Export where dShipmentDate = '"+str+"'");
}
else if(cbName.equals("货品编号")){
prep = conn.prepareStatement("select * from Export where cCommodityId= ?");
prep.setString(1,str);
if(str.equals("")){
JOptionPane.showMessageDialog(ExportMainPanel.getExportMainPanel(), "请输入货品编号!");
return;
}else if(!str.matches("^\\d+$")){
JOptionPane.showMessageDialog(ExportMainPanel.getExportMainPanel(), "货品编号只能为数字!");
return;
}
}
else if(cbName.equals("仓库编号")){
prep = conn.prepareStatement("select * from Export where cStorageCode= ?");
prep.setString(1,str);
if(str.equals("")){
JOptionPane.showMessageDialog(ExportMainPanel.getExportMainPanel(), "请输入仓库编号!");
return;
}else if(!str.matches("^\\d+$")){
JOptionPane.showMessageDialog(ExportMainPanel.getExportMainPanel(), "仓库编号只能为数字!");
return;
}
}
rs = prep.executeQuery();// 将查询得到的结果集给rs
while (rs.next()) {
String iExportId = rs.getString(1);
String cEmployeeId = rs.getString(2);
String dShipmentDate = rs.getString(3);
String cCommodityId = rs.getString(4);
String mPrice = rs.getString(5);
String iAmount = rs.getString(6);
String cStorageCode = rs.getString(7);

String[] str_row = { iExportId, cEmployeeId, dShipmentDate,
cCommodityId, mPrice, iAmount, cStorageCode }; // 将一行的数据存在str_row
// 字符串数组里
mm.addRow(str_row);// 添加在表模板中
}
rs.close();
prep.close();
ExportMainPanel.getExportMainPanel().jtable.setModel(mm);
ExportMainPanel.getExportMainPanel().scp.add(ExportMainPanel.getExportMainPanel().jscrollpane);
// 将加载了表的滚动条在JFrame中显示
}catch(Exception ee){
ee.printStackTrace();
}
}
if(btn==btn2){
Main.getMain().setVisible(true);
ExportMainPanel.getExportMainPanel().setVisible(false);
}
}

public ExportSelectPanel(){
cb = new JComboBox();
tfd = new JTextField(10);
lb = new JLabel("日期格式2008-01-01 00:00:00");
pSelect = new JPanel();
btn1 = new JButton("确定查询");
btn2 = new JButton("返回主界面");
cb.addItem("入库单号");
cb.addItem("经手人ID");
cb.addItem("入库日期");
cb.addItem("货品编号");
cb.addItem("仓库编号");

cb.addActionListener(this);

btn1.addActionListener(this);
btn2.addActionListener(this);

pSelect.add(cb);
pSelect.add(tfd);
pSelect.add(btn1);
pSelect.add(btn2);
}
}
希望这段代码可以帮到你

热心网友 时间:2024-10-19 15:31

希望这个代码对你有帮助!:
import java.awt.*;
import javax.swing.*;
import javax.swing.table.*;
public class TableModelTest extends JFrame {

private JTable table;
private AbstractTableModel myModel;
public TableModelTest(){
myModel=new MyTableModel();
table=new JTable(myModel);
JScrollPane jsp=new JScrollPane(table);
Container cp=getContentPane();
cp.add(jsp,BorderLayout.CENTER);

}
public static void main(String[] args) {
TableModelTest tmt=new TableModelTest();
tmt.setTitle("表模型测试");
tmt.setSize(800,600);
tmt.setVisible(true);

}

}
class MyTableModel extends AbstractTableModel{
Object[][] rowData={
{"e01","郭旭东","男","1986-5-26","5000","d01"},
{"e01","郭旭东","男","1986-5-26","5000","d01"},
{"e01","郭旭东","男","1986-5-26","5000","d01"},
{"e01","郭旭东","男","1986-5-26","5000","d01"},
};
String[] columnName={"职工工号","职工姓名","性别","出生年月","工资","部门编号"};
public int getRowCount(){
return rowData.length;
}
public int getColumnCount(){
return rowData[0].length;
}
public String getColumnName(int c){
return columnName[c];
}
public Object getValueAt(int row,int column){
return rowData[row][column];
}
}

热心网友 时间:2024-10-19 15:30

理解不能
你把JTable放到哪,不就在哪显示吗?

热心网友 时间:2024-10-19 15:35

可以添加一个新的JPanel,然后在根据不同的用途调用设置不同的控件,这样就不用新建那么多界面了,一个就能够完成所有的功能!使用的时候就像windows下的不同选项卡一样,但是还是公用同一个窗口!

热心网友 时间:2024-10-19 15:35

package com.gxa.Export;

import java.awt.event.*;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

import com.gxa.Main.Main;
import com.gxa.Pub.*;
import javax.swing.*;
import javax.swing.table.DefaultTableModel;

public class ExportSelectPanel implements ActionListener{
JPanel pSelect;
JComboBox cb;
JTextField tfd;
JLabel lb;
JButton btn1,btn2;

public void actionPerformed(ActionEvent e) {
Object btn = e.getSource();
PreparedStatement prep = null;
ResultSet rs;
if(btn==cb && cb.getSelectedItem().equals("入库日期")){
pSelect.add(lb);
}
if(btn==btn1){
Object cbName = cb.getSelectedItem();
String[] col = { "iExportId", "cEmployeeId", "dShipmentDate",
"cGoodId", "mPrice", "iAmount", "cStorageCode" };
DefaultTableModel mm = new DefaultTableModel(col, 0); // 定义一个表的模板
String str = tfd.getText();

try{
Connection conn = Conn.getCon().con;
if(tfd.getText().length()==0){
prep = conn.prepareStatement("select * from Export");
}
else if(cbName.equals("入库单号")){
prep = conn.prepareStatement("select * from Export where iExportId= ?");
prep.setString(1,str);
if(str.equals("")){
JOptionPane.showMessageDialog(ExportMainPanel.getExportMainPanel(), "请输入入库单号!");
return;
}else if(!str.matches("^\\d+$")){
JOptionPane.showMessageDialog(ExportMainPanel.getExportMainPanel(), "入库单号只能为数字!");
return;
}
}
else if(cbName.equals("经手人ID")){
prep = conn.prepareStatement("select * from Export where cEmployeeId= ?");
prep.setString(1,str);
if(str.equals("")){
JOptionPane.showMessageDialog(ExportMainPanel.getExportMainPanel(), "请输入经手人!");
return;
}else if(!str.matches("^\\d+$")){
JOptionPane.showMessageDialog(ExportMainPanel.getExportMainPanel(), "经手人只能为数字!");
return;
}
}
else if(cbName.equals("入库日期")){
prep = conn.prepareStatement("select * from Export where dShipmentDate = '"+str+"'");
}
else if(cbName.equals("货品编号")){
prep = conn.prepareStatement("select * from Export where cCommodityId= ?");
prep.setString(1,str);
if(str.equals("")){
JOptionPane.showMessageDialog(ExportMainPanel.getExportMainPanel(), "请输入货品编号!");
return;
}else if(!str.matches("^\\d+$")){
JOptionPane.showMessageDialog(ExportMainPanel.getExportMainPanel(), "货品编号只能为数字!");
return;
}
}
else if(cbName.equals("仓库编号")){
prep = conn.prepareStatement("select * from Export where cStorageCode= ?");
prep.setString(1,str);
if(str.equals("")){
JOptionPane.showMessageDialog(ExportMainPanel.getExportMainPanel(), "请输入仓库编号!");
return;
}else if(!str.matches("^\\d+$")){
JOptionPane.showMessageDialog(ExportMainPanel.getExportMainPanel(), "仓库编号只能为数字!");
return;
}
}
rs = prep.executeQuery();// 将查询得到的结果集给rs
while (rs.next()) {
String iExportId = rs.getString(1);
String cEmployeeId = rs.getString(2);
String dShipmentDate = rs.getString(3);
String cCommodityId = rs.getString(4);
String mPrice = rs.getString(5);
String iAmount = rs.getString(6);
String cStorageCode = rs.getString(7);

String[] str_row = { iExportId, cEmployeeId, dShipmentDate,
cCommodityId, mPrice, iAmount, cStorageCode }; // 将一行的数据存在str_row
// 字符串数组里
mm.addRow(str_row);// 添加在表模板中
}
rs.close();
prep.close();
ExportMainPanel.getExportMainPanel().jtable.setModel(mm);
ExportMainPanel.getExportMainPanel().scp.add(ExportMainPanel.getExportMainPanel().jscrollpane);
// 将加载了表的滚动条在JFrame中显示
}catch(Exception ee){
ee.printStackTrace();
}
}
if(btn==btn2){
Main.getMain().setVisible(true);
ExportMainPanel.getExportMainPanel().setVisible(false);
}
}

public ExportSelectPanel(){
cb = new JComboBox();
tfd = new JTextField(10);
lb = new JLabel("日期格式2008-01-01 00:00:00");
pSelect = new JPanel();
btn1 = new JButton("确定查询");
btn2 = new JButton("返回主界面");
cb.addItem("入库单号");
cb.addItem("经手人ID");
cb.addItem("入库日期");
cb.addItem("货品编号");
cb.addItem("仓库编号");

cb.addActionListener(this);

btn1.addActionListener(this);
btn2.addActionListener(this);

pSelect.add(cb);
pSelect.add(tfd);
pSelect.add(btn1);
pSelect.add(btn2);
}
}
希望这段代码可以帮到你

热心网友 时间:2024-10-19 15:32

可以添加一个新的JPanel,然后在根据不同的用途调用设置不同的控件,这样就不用新建那么多界面了,一个就能够完成所有的功能!使用的时候就像windows下的不同选项卡一样,但是还是公用同一个窗口!

热心网友 时间:2024-10-19 15:29

理解不能
你把JTable放到哪,不就在哪显示吗?

热心网友 时间:2024-10-19 15:34

希望这个代码对你有帮助!:
import java.awt.*;
import javax.swing.*;
import javax.swing.table.*;
public class TableModelTest extends JFrame {

private JTable table;
private AbstractTableModel myModel;
public TableModelTest(){
myModel=new MyTableModel();
table=new JTable(myModel);
JScrollPane jsp=new JScrollPane(table);
Container cp=getContentPane();
cp.add(jsp,BorderLayout.CENTER);

}
public static void main(String[] args) {
TableModelTest tmt=new TableModelTest();
tmt.setTitle("表模型测试");
tmt.setSize(800,600);
tmt.setVisible(true);

}

}
class MyTableModel extends AbstractTableModel{
Object[][] rowData={
{"e01","郭旭东","男","1986-5-26","5000","d01"},
{"e01","郭旭东","男","1986-5-26","5000","d01"},
{"e01","郭旭东","男","1986-5-26","5000","d01"},
{"e01","郭旭东","男","1986-5-26","5000","d01"},
};
String[] columnName={"职工工号","职工姓名","性别","出生年月","工资","部门编号"};
public int getRowCount(){
return rowData.length;
}
public int getColumnCount(){
return rowData[0].length;
}
public String getColumnName(int c){
return columnName[c];
}
public Object getValueAt(int row,int column){
return rowData[row][column];
}
}
声明声明:本网页内容为用户发布,旨在传播知识,不代表本网认同其观点,若有侵权等问题请及时与本网联系,我们将在第一时间删除处理。E-MAIL:11247931@qq.com
Linux系统安装FTP服务器 Linux系统的网络文件共享 建筑的七盏明灯的内容简介 面向对象设计七大原则 简单说 交互设计七大定律 交互设计的“根”——七大定律 交互设计原则和理论2——七大定律 七大设计原则 附近的加油站有哪些 附近的加油站有哪些地方 轩辕剑4黑龙舞兮云飞扬 玩儿到从地裂迷宫返回东海滨时,一播放动画就应... swing中,把弹出的frame置顶,别的地方都不能点击,必须关闭frame以后才能点... LXTL弹性填料弹性填料结构 ...了一个轩辕剑三云和山的彼端还有一个轩辕剑四黑龙舞兮云飞扬但是运行... 环保弹性立体填料产品特点: 急!轩辕剑4黑龙舞兮云飞扬一点游戏就弹出了两个乱码的框框,点了就退出... 怎么把32位系统升级成64位的系统呢? 煌黑龙的翼膜要怎么才能拿到? 煌黑龙破翼了,为啥没有翼膜??? 每月养老金6400元,打入医保卡里的金额是多少? 柠檬树柠檬导航7 电视版的内涵段子社区 为什么进不去了啊 wps为什么无法打开文件了? win7是64位是什么意思? 经常感冒是不是身体缺乏什么东西?还是别的原因? ...想请问一下浙江工商大学离西湖有多远,离浙大又有多远! 这幅图上的字翻译后是什么意思?看不懂,求大神解围 ...片硬币的全文翻译!!!如果谁有那就麻烦发一下!谢谢!我很急!_百度知 ... ...打到五号位的“慈世平”,为何当年在CBA打了15场比赛就被裁了... ...为什么阿泰斯特在CBA打了15场球就被四川队裁掉? 水处理弹性填料产品简介 swing 中如何实现单击一个按钮在同一层次弹出一个txt文本框悬浮在原界面... 我想用Swing实现单击按钮后能弹出一个新窗口!!这是我的代码!谢谢!_百度... 从通河新村到莲花路1978号怎么走? 谢谢^_^ 求从宝山到最方便的家乐福是哪个?坐车怎么走? 我想在swing的菜单按钮中,按下按钮,弹出一个小窗体,在小窗体上设置参数... 狂蛇惊魂/死里逃生2剧情梗概 狂蛇惊魂的基本信息 狂蛇惊魂/死里逃生2幕后花絮 win7x64是什么意思 依古姿妮几线品牌 从学生/实习生的眼光看意大利顶级灯具依古姿妮 iGuzzini灯具品牌_百 ... 上海奉贤区南桥车站到环城北路的依古姿妮乘什么车哪里下? 魅族MX3通话声音小 上海功川机械有限公司怎么样 “为谁折赠春色”的出处是哪里 魅族3通话声音太小,刷固件也没用。怎么办? “已见一枝”的出处是哪里 答应做你女朋友的经典台词 现代制紫砂壶大师名单