Java中怎么在一个窗体点击一个access窗体按钮打开表另一个窗体?

欢迎加入我们,一同切磋技术。 &
用户名: &&&
密 码: &
共有 2922 人关注过本帖
标题:Java页面设计,页面已经弄成绝对对位,如何实现点击一个按钮出现另一个按钮 ...
等 级:论坛游民
帖 子:76
专家分:48
结帖率:90.91%
&&已结贴√
&&问题点数:20&&回复次数:9&&&
Java页面设计,页面已经弄成绝对对位,如何实现点击一个按钮出现另一个按钮?
Java页面设计,页面已经弄成绝对对位,如何实现点击一个按钮出现另一个按钮?
如果换成布局管理,就可以实现,但是弄绝对定位,弄不成啊。。。
我给我的代码:
程序代码:
package 测试的项目;
import java.awt.event.ActionE
import java.awt.event.ActionL
import javax.swing.JB
import javax.swing.JF
import javax.swing.JP@SuppressWarnings(&serial&)
public class ButtonFrame extends JFrame {
&public ButtonFrame() {
&&buttonPanel = new JPanel();
&&buttonPanel.setLayout(null);
&&setSize(500, 500);
&&makeButton();&&
&&add(buttonPanel);
&public void makeButton() {
&&JButton buttonFather = new JButton(&I'm father&);
&&buttonFather.addActionListener(new ActionListener() {
&&&public void actionPerformed(ActionEvent event) {
&&& addButton(event);
&&buttonFather.setBounds(20, 20, 80, 40);
&&buttonPanel.add(buttonFather);
&private void addButton(ActionEvent event) {
&&JButton buttonSon = new JButton(&I'm son&);
&&JButton f = new JButton(&123&);
&&buttonSon.setBounds(20, 80, 80, 40);
&&f.setBounds(20, 120, 80, 40);
&&buttonPanel.add(buttonSon);
&&buttonPanel.add(f);
&&this.validate();
&private JPanel buttonP
&public static void main(String[] args) {
&&new ButtonFrame().setVisible(true);
哪一位大神,教教我呗
搜索更多相关主题的帖子:
等 级:论坛游民
帖 子:76
专家分:48
谁教教我呀!!!!!!!
来 自:湖南
等 级:版主
威 望:67
帖 子:1354
专家分:5721
&&得分:20&
程序代码:import java.awt.event.ActionE
import java.awt.event.ActionL
import javax.swing.JB
import javax.swing.JF
public class ButtonFrame extends JFrame
&&& private static final long serialVersionUID=1L;
&&& private static JButton btnA;
&&& private static JButton btnB;
&&& public ButtonFrame()
&&&&&&&&btnA=new JButton(&A&);
&&&&&&&&btnB=new JButton(&B&);
&&&&&&&&btnB.setVisible(false);
&&&&&&&&setLayout(null);
&&&&&&&&btnA.setBounds(20, 40, 60, 32);
&&&&&&&&btnB.setBounds(20, 120, 60, 32);
&&&&&&&&btnA.addActionListener(new ActionListener()
&&&&&&&&&&&&public void actionPerformed(ActionEvent e)
&&&&&&&&&&&&{
&&&&&&&&&&&&&&& btnB.setVisible(true);
&&&&&&&&&&&&&&& btnA.setVisible(false);
&&&&&&&&&&&&}
&&&&&&&&});
&&&&&&&&btnB.addActionListener(new ActionListener()
&&&&&&&&&&&&public void actionPerformed(ActionEvent e)
&&&&&&&&&&&&{
&&&&&&&&&&&&&&& btnA.setVisible(true);
&&&&&&&&&&&&&&& btnB.setVisible(false);
&&&&&&&&&&&&}
&&&&&&&&});
&&&&&&&&add(btnA);
&&&&&&&&add(btnB);
&&&&&&&&setSize(400, 400);
&&&&&&&&setVisible(true);
&&& public static void main(String[] args)
&&&&&&&&new ButtonFrame();
等 级:论坛游民
帖 子:76
专家分:48
回复 3楼 林月儿
版主,我有个问题,你的例子是通过设置显示不显示来实现,但是我的按钮里面的内容要通过输入键盘输入来设置呢?该如何弄?
来 自:湖南
等 级:版主
威 望:67
帖 子:1354
专家分:5721
键盘输入是输入到控制台还是界面的控件?说清楚!
等 级:论坛游民
帖 子:76
专家分:48
回复 5楼 林月儿
版主,就比如,有一个按钮,里面的内容是A。在这个按钮之前,有一个输入框,在这个输入框输入一个数字,比如输入是3,那么按这个按钮之后,就会出现三个按钮,里面的内容是B。但是如果输入的是2,那么就出现两个。是这样的。
等 级:论坛游民
帖 子:24
专家分:25
帮你顶上来
我赢职场邀请码
来 自:湖南
等 级:版主
威 望:67
帖 子:1354
专家分:5721
顶什么顶?这是什么问题哦
等 级:论坛游民
帖 子:76
专家分:48
回复 8楼 林月儿
等 级:论坛游民
帖 子:76
专家分:48
回复 8楼 林月儿
版主,那你帮我看看我另外的一个帖子行么,mysql的
版权所有,并保留所有权利。
Powered by , Processed in 0.037815 second(s), 8 queries.
Copyright&, BCCN.NET, All Rights Reserved> 问题详情
某窗体中有一个命令按钮,在“窗体”视图中单击该命令按钮可以打开另一个窗体,则需要执行的宏操作是
悬赏:0&答案豆
提问人:匿名网友
发布时间:
某窗体中有一个命令按钮,在“窗体”视图中单击该命令按钮可以打开另一个窗体,则需要执行的宏操作是()。A.OpenQueryB.OpenReportC.OpenWindowD.OpenForm请帮忙给出正确答案和分析,谢谢!
为您推荐的考试题库
您可能感兴趣的试题
1关于更新查询,以下说法中不正确的是(  )。A.使用更新查询可以将已有表中满足条件的记录进行更新B.使用更新查询,一次只能对一条记录进行更改C.使用更新查询后就不能再恢复数据了D.更新查询的效率比在数据表中更新数据的效率高2要实现报表的分组统计,其操作区域是(  )。A.报表页眉或报表页脚B.页面页眉或页面页脚C.主体区域D.组页眉或组页脚区域3阅读下面的程序: Option Base lPrivate Sub swapa0 As IntegerFori_1t010,2t=a(i)a(i)=a(l0一i+1)a(10-i+1)=tNextiEnd SubPrivate Sub Form. Click0Dimx00)AsIntegerFori=l t010x(i)=*2NextiSwapx0Fori=l to 10Debug.Printx(i); NextiEndSub程序运行后,输出的结果为(  )。A.1 2 3 4 5 6 7 8 9 10B.2 4 6 8 10 12 14 16 18 20C.20 18 16 14 12 10 8 6 4 2D.显示出错信息4创建报表的数据来源不能是(  )。A.任意的B.一个多表创建的查询C.一个单表创建的查询D.一个表
我有更好的答案
请先输入下方的验证码查看最佳答案
图形验证:
验证码提交中……
找答案会员
享三项特权
找答案会员
享三项特权
找答案会员
享三项特权
选择支付方式:
支付宝付款
郑重提醒:支付后,系统自动为您完成注册
请使用微信扫码支付(元)
支付后,系统自动为您完成注册
遇到问题请联系在线客服QQ:
请您不要关闭此页面,支付完成后点击支付完成按钮
遇到问题请联系在线客服QQ:
恭喜您!升级VIP会员成功
常用邮箱:
用于找回密码
确认密码:查看:14013|回复:13
两个类在同一个包&&可是点击按钮出错误。。那个帮下&&谢谢
最有价值午饭
问题和代码一起贴出来。
import java.awt.BorderL
import java.awt.C
import java.awt.C
import java.awt.FlowL
import java.awt.event.ActionE
import java.awt.event.ActionL
import javax.swing.ImageI
import javax.swing.JB
import javax.swing.JF
import javax.swing.JL
import javax.swing.JP
public class face extends JFrame implements ActionListener{
& & & & private static final long serialVersionUID = 1L;
& & & & private JL
& & & & private JLabel label1;
& & & & private JButton button1;
& & & & private JButton button2;
& & & & private JButton button3;
& & & & JPanel panel3;
& & & & JPanel panel4;
& & & & JLabel label2;
& & & & JButton button4;
& & & & JButton button5;
& & & & JButton button6;
& & & & JButton button7;
& & & & JButton button8;
& & & & JButton button9;
& & & & JButton button10;
& & & & public face()
& & & & & & & & setTitle(&HOTLE SERVE————欢迎您!& && && && &&&服务电话:&);
& & & & & & & & setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
& & & & & & & & JPanel panel1=new JPanel();
& & & & & & & & panel1.setBackground(Color.RED);
& & & & & & & & JPanel panel2=new JPanel(new FlowLayout());
& & & & & & & & ImageIcon image=new ImageIcon(&image\\login.jpg&);//图片路径
& & & & & & & & label1=new JLabel(image);
& & & & & & & & label=new JLabel(&Welcome to you!&);
& & & & & & & & button1=new JButton(&订房&);
& & & & & & & & button2=new JButton(&退房&);
& & & & & & & & button3=new JButton(&反馈意见&);
& & & & & & & &
& & & & & & & & button1.addActionListener(this);//增加监听器
& & & & & & & & button2.addActionListener(this);
& & & & & & & & button3.addActionListener(this);
& & & & & & & &
& & & & & & & & panel1.add(label);
& & & & & & & & panel2.add(button1);
& & & & & & & & panel2.add(button2);
& & & & & & & & panel2.add(button3);
& & & & & & & &
& & & & & & & & Container myCP=getContentPane();//将组件加入到内容面板中
& & & & & & & & myCP.add(panel1,BorderLayout.NORTH);
& & & & & & & & myCP.add(panel2,BorderLayout.SOUTH);
& & & & & & & & myCP.add(label1,BorderLayout.CENTER);
& & & & & & & & setSize(600,600);
public void actionPerformed(ActionEvent e)
& & & & if(e.getSource()==button1);
& & & & new order().setVisible(true);
public static void main(String[] args)
& & & & face window =new face();
& & & & window.setVisible(true);
import java.awt.BorderL
import java.awt.C
import java.awt.C
import javax.swing.JB
import javax.swing.JF
import javax.swing.JL
import javax.swing.JP
public class order extends JFrame {
& & & & /**
& & & &&&*
& & & &&&*/
& & & & public static final long serialVersionUID = 2L;
& & & & JPanel panel3;
& & & & JPanel panel4;
& & & & JLabel label2;
& & & & JButton button4;
& & & & JButton button5;
& & & & JButton button6;
& & & & JButton button7;
& & & & JButton button8;
& & & & JButton button9;
& & & & JButton button10;
& & & & public order(){
& & & & setTitle(&退票服务————欢迎入住&);
& & & & setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
& & & & panel3=new JPanel();
& & & & panel3.setBackground(Color.RED);
& & & & panel4=new JPanel();
& & & & label2=new JLabel(&Welcome to you!&);
& & & & panel3.add(label2);
& & & & panel4.add(button4);
& & & & panel4.add(button5);
& & & & panel4.add(button6);
& & & & panel4.add(button7);
& & & & panel4.add(button8);
& & & & panel4.add(button9);
& & & & panel4.add(button10);
& & & & button4=new JButton(&查看101号房间&);
& & & & button5=new JButton(&查看102号房间&);
& & & & button6=new JButton(&查看103号房间&);
& & & & button7=new JButton(&查看104号房间&);
& & & & button8=new JButton(&查看105号房间&);
& & & & button9=new JButton(&查看106号房间&);
& & & & button10=new JButton(&查看107号房间&);
& & & & Container orCP=getContentPane();
& & & & orCP.add(panel3,BorderLayout.NORTH);
& & & & orCP.add(panel3,BorderLayout.CENTER);
& & & & setSize(600,600);
Exception in thread &AWT-EventQueue-0& java.lang.NullPointerException
& & & & at java.awt.Container.addImpl(Unknown Source)
& & & & at java.awt.Container.add(Unknown Source)
& & & & at hotle.order.&init&(order.java:37)
& & & & at hotle.face.actionPerformed(face.java:66)
& & & & at javax.swing.AbstractButton.fireActionPerformed(Unknown Source)
& & & & at javax.swing.AbstractButton$Handler.actionPerformed(Unknown Source)
& & & & at javax.swing.DefaultButtonModel.fireActionPerformed(Unknown Source)
& & & & at javax.swing.DefaultButtonModel.setPressed(Unknown Source)
& & & & at javax.swing.plaf.basic.BasicButtonListener.mouseReleased(Unknown Source)
& & & & at ponent.processMouseEvent(Unknown Source)
& & & & at javax.swing.JComponent.processMouseEvent(Unknown Source)
& & & & at ponent.processEvent(Unknown Source)
& & & & at java.awt.Container.processEvent(Unknown Source)
& & & & at ponent.dispatchEventImpl(Unknown Source)
& & & & at java.awt.Container.dispatchEventImpl(Unknown Source)
& & & & at ponent.dispatchEvent(Unknown Source)
& & & & at java.awt.LightweightDispatcher.retargetMouseEvent(Unknown Source)
& & & & at java.awt.LightweightDispatcher.processMouseEvent(Unknown Source)
& & & & at java.awt.LightweightDispatcher.dispatchEvent(Unknown Source)
& & & & at java.awt.Container.dispatchEventImpl(Unknown Source)
& & & & at java.awt.Window.dispatchEventImpl(Unknown Source)
& & & & at ponent.dispatchEvent(Unknown Source)
& & & & at java.awt.EventQueue.dispatchEventImpl(Unknown Source)
& & & & at java.awt.EventQueue.access$400(Unknown Source)
& & & & at java.awt.EventQueue$2.run(Unknown Source)
& & & & at java.awt.EventQueue$2.run(Unknown Source)
& & & & at java.security.AccessController.doPrivileged(Native Method)
& & & & at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
& & & & at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
& & & & at java.awt.EventQueue$3.run(Unknown Source)
& & & & at java.awt.EventQueue$3.run(Unknown Source)
& & & & at java.security.AccessController.doPrivileged(Native Method)
& & & & at java.security.AccessControlContext$1.doIntersectionPrivilege(Unknown Source)
& & & & at java.awt.EventQueue.dispatchEvent(Unknown Source)
& & & & at java.awt.EventDispatchThread.pumpOneEventForFilters(Unknown Source)
& & & & at java.awt.EventDispatchThread.pumpEventsForFilter(Unknown Source)
& & & & at java.awt.EventDispatchThread.pumpEventsForHierarchy(Unknown Source)
& & & & at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
& & & & at java.awt.EventDispatchThread.pumpEvents(Unknown Source)
& & & & at java.awt.EventDispatchThread.run(Unknown Source)
这个是出现的问题
引用:原帖由 iceworldvip 于
16:04 发表
问题和代码一起贴出来。 发出来 了&&帮我看看&&谢谢
最有价值午饭
引用:原帖由 mlxyeah 于
16:08 发表
发出来 了&&帮我看看&&谢谢 首先,你的问题是order类中的按钮还没有实例化就添加到panel中,这样一定会报空指针的。
还有你书写规范需要注意,类名怎么能全是小写呢?
还有代码的格式问题,需要规范一下!
把我说的问题修改一下,然后再试试!
引用:原帖由 iceworldvip 于
16:15 发表
首先,你的问题是order类中的按钮还没有实例化就添加到panel中,这样一定会报空指针的。
还有你书写规范需要注意,类名怎么能全是小写呢?
还有代码的格式问题,需要规范一下!
把我说的问题修改一下,然后再试试! ... 谢谢你&&我去试试
引用:原帖由 iceworldvip 于
16:15 发表
首先,你的问题是order类中的按钮还没有实例化就添加到panel中,这样一定会报空指针的。
还有你书写规范需要注意,类名怎么能全是小写呢?
还有代码的格式问题,需要规范一下!
把我说的问题修改一下,然后再试试! ... 我想实现的是点击“订房”按钮&&出来一个新的窗口。这样能实现吗?思路是否是正确的?
最有价值午饭
引用:原帖由 mlxyeah 于
16:36 发表
我想实现的是点击“订房”按钮&&出来一个新的窗口。这样能实现吗?思路是否是正确的? 复制内容到剪贴板代码:import java.awt.BorderL
import java.awt.C
import java.awt.C
import java.awt.FlowL
import java.awt.event.ActionE
import java.awt.event.ActionL
import javax.swing.ImageI
import javax.swing.JB
import javax.swing.JF
import javax.swing.JL
import javax.swing.JP
public class Face extends JFrame implements ActionListener {
& & private static final long serialVersionUID = 1L;
& & private JL
& & private JLabel label1;
& & private JButton button1;
& & private JButton button2;
& & private JButton button3;
& & JPanel panel3;
& & JPanel panel4;
& & JLabel label2;
& & JButton button4;
& & JButton button5;
& & JButton button6;
& & JButton button7;
& & JButton button8;
& & JButton button9;
& & JButton button10;
& & public Face() {
& && &&&setTitle(&HOTLE SERVE————欢迎您!& && && && &&&服务电话:&);
& && &&&setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
& && &&&JPanel panel1 = new JPanel();
& && &&&panel1.setBackground(Color.RED);
& && &&&JPanel panel2 = new JPanel(new FlowLayout());
& && &&&ImageIcon image = new ImageIcon(&image\\login.jpg&);//图片路径
& && &&&label1 = new JLabel(image);
& && &&&label = new JLabel(&Welcome to you!&);
& && &&&button1 = new JButton(&订房&);
& && &&&button2 = new JButton(&退房&);
& && &&&button3 = new JButton(&反馈意见&);
& && &&&button1.addActionListener(this);//增加监听器
& && &&&button2.addActionListener(this);
& && &&&button3.addActionListener(this);
& && &&&panel1.add(label);
& && &&&panel2.add(button1);
& && &&&panel2.add(button2);
& && &&&panel2.add(button3);
& && &&&Container myCP = getContentPane();//将组件加入到内容面板中
& && &&&myCP.add(panel1, BorderLayout.NORTH);
& && &&&myCP.add(panel2, BorderLayout.SOUTH);
& && &&&myCP.add(label1, BorderLayout.CENTER);
& && &&&setSize(600, 600);
& & public void actionPerformed(ActionEvent e) {
& && &&&if (e.getSource() == button1)
& && && && &;
& && &&&new Order().setVisible(true);
& & public static void main(String[] args) {
& && &&&Face window = new Face();
& && &&&window.setVisible(true);
}还没有侬好么?
你试试吧!很明了了!如果想只保留一个窗口的话,那么在显示预订窗口的时候隐藏主窗口。
就是把实例化放在add方法之前。
然后你的panel4还需要加入到container容器中。
祝你好运吧!
引用:原帖由 iceworldvip 于
16:45 发表
import java.awt.BorderL
import java.awt.C
import java.awt.C
import java.awt.FlowL
import java.awt.event.ActionE
import java.awt.event.ActionL
import javax.swin ... 谢谢&&搞好了&&!!!
import java.awt.BorderL
import java.awt.C
引用:原帖由 mlxyeah 于
19:31 发表
谢谢&&搞好了&&!!! 怎么弄哦
public void actionPerformed(ActionEvent e) {
& & & &&&if(e.getSource()==b1);
& &&&new LoginFrame().setVisible(true);
b1这里报错&&怎么回事?

我要回帖

更多关于 html点击按钮弹出窗体 的文章

 

随机推荐