java中如何从一个窗口button按钮跳转到另一个窗口 205
例:第一个窗口importjava.awt.Dimension;importjava.awt.FlowLayout;importjava.awt.Toolkit;impo...
例:
第一个窗口import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Toolkit;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
class picture2 extends JFrame{
private JLabel aa=new JLabel("输入饮料种类 ");
private JButton c1=new JButton("啤酒/6元");
private JButton c2=new JButton("冰红茶/3元");
private JButton c3=new JButton("橘子汁/2元");
private JButton c4=new JButton("牛奶/1元");
public picture2(){
setTitle("自动售货机");
setLayout(new FlowLayout());
add(aa);
add(c1);
add(c2);
add(c3);
add(c4);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Dimension screenSize=Toolkit.getDefaultToolkit().getScreenSize();
Dimension frameSize=new Dimension(300,100);
if(frameSize.height>screenSize.height){
frameSize.height=screenSize.height;
}
if(frameSize.width>screenSize.width){
frameSize.width=screenSize.width;
}
setLocation(((screenSize.width-frameSize.width)/2),
((screenSize.height-frameSize.height)/2));
setSize(frameSize);
this.setResizable(false);
this.setVisible(true);
}
}
public class first {
public static void main(String[] args) {
picture2 win1=new picture2();
}
}
第二个窗口:
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Toolkit;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
class picture1 extends JFrame{
private JLabel aa1=new JLabel("请输入数量");
private JTextField aa2=new JTextField(15);
private JButton aa3=new JButton("确定");
public picture1(){
setTitle("自动售货机");
setLayout(new FlowLayout());
add(aa1);
add(aa2);
add(aa3);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Dimension screenSize=Toolkit.getDefaultToolkit().getScreenSize();
Dimension frameSize=new Dimension(300,100);
if(frameSize.height>screenSize.height){
frameSize.height=screenSize.height;
}
if(frameSize.width>screenSize.width){
frameSize.width=screenSize.width;
}
setLocation(((screenSize.width-frameSize.width)/2),
((screenSize.height-frameSize.height)/2));
setSize(frameSize);
this.setResizable(false);
this.setVisible(true);
}
}
public class second {
public static void main(String[] args) {
picture1 win2=new picture1();
}
}
要怎么改求教 谢谢
最好帮忙举例改一下 说下原理 谢谢了 顺便问一下 链接数据库 前面添加请投币 +钱数
如何填加到后面的找零里 找零多少元 展开
第一个窗口import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Toolkit;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
class picture2 extends JFrame{
private JLabel aa=new JLabel("输入饮料种类 ");
private JButton c1=new JButton("啤酒/6元");
private JButton c2=new JButton("冰红茶/3元");
private JButton c3=new JButton("橘子汁/2元");
private JButton c4=new JButton("牛奶/1元");
public picture2(){
setTitle("自动售货机");
setLayout(new FlowLayout());
add(aa);
add(c1);
add(c2);
add(c3);
add(c4);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Dimension screenSize=Toolkit.getDefaultToolkit().getScreenSize();
Dimension frameSize=new Dimension(300,100);
if(frameSize.height>screenSize.height){
frameSize.height=screenSize.height;
}
if(frameSize.width>screenSize.width){
frameSize.width=screenSize.width;
}
setLocation(((screenSize.width-frameSize.width)/2),
((screenSize.height-frameSize.height)/2));
setSize(frameSize);
this.setResizable(false);
this.setVisible(true);
}
}
public class first {
public static void main(String[] args) {
picture2 win1=new picture2();
}
}
第二个窗口:
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Toolkit;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
class picture1 extends JFrame{
private JLabel aa1=new JLabel("请输入数量");
private JTextField aa2=new JTextField(15);
private JButton aa3=new JButton("确定");
public picture1(){
setTitle("自动售货机");
setLayout(new FlowLayout());
add(aa1);
add(aa2);
add(aa3);
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Dimension screenSize=Toolkit.getDefaultToolkit().getScreenSize();
Dimension frameSize=new Dimension(300,100);
if(frameSize.height>screenSize.height){
frameSize.height=screenSize.height;
}
if(frameSize.width>screenSize.width){
frameSize.width=screenSize.width;
}
setLocation(((screenSize.width-frameSize.width)/2),
((screenSize.height-frameSize.height)/2));
setSize(frameSize);
this.setResizable(false);
this.setVisible(true);
}
}
public class second {
public static void main(String[] args) {
picture1 win2=new picture1();
}
}
要怎么改求教 谢谢
最好帮忙举例改一下 说下原理 谢谢了 顺便问一下 链接数据库 前面添加请投币 +钱数
如何填加到后面的找零里 找零多少元 展开
1个回答
2017-06-14
展开全部
和打开第1个窗口一样,打开新窗口,,,,,,,,,但,最好是先隐藏原窗口、关闭新开的窗口,再显示原窗口
~
~
~
~
~
~
追问
说的具体点 谢谢 用什么代码
说的具体点 谢谢 用什么代码
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询