
正文
菜单跳转java代码 java菜单栏中跳转
提示:扫一扫查出行【扫一扫了解最新限行尾号】
复制提示
java中如何做到界面的跳转?
假如有两个frame,分别为frame1,frame2,frame1加个按钮实现跳转.frame1代码如下
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
public class frame1 extends JFrame implements ActionListener{
/**
* @param args
*/
private JButton jb;
public frame1()
{
this.setSize(300, 200);
this.setLocation(300, 400);
jb=new JButton("跳转");
this.add(jb);
jb.addActionListener(this);//加入事件监听
this.setVisible(true);
}
public static void main(String[] args) {
// TODO Auto-generated method stub
frame1 frame=new frame1();
}
@Override
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
if(e.getSource()==jb)
{
this.dispose();//点击按钮时frame1销毁,new一个frame2
new frame2();
}
}
}
frame2是个单纯的界面
import javax.swing.JButton;
import javax.swing.JFrame;
public class frame2 extends JFrame{
/**
* @param args
*/
public frame2()
{
this.setSize(300, 200);
this.setLocation(300, 400);
this.setVisible(true);
}
public static void main(String[] args) {
// TODO Auto-generated method stub
frame2 frame=new frame2();
}
}
相关问答
Q1: java中如何实现界面的跳转???
Servlet是一种独立于平台和协议菜单跳转java代码的服务器端的Java应用程序,可以生成动态的Web页面。 它担当Web浏览器或其菜单跳转java代码他HTTP客户程序发出请求,与HTTP服务器上的数据库或应用程序之间的中间层。
Servlet是一个接口,它的service方法是每当用户发出请求,就会被调用。但是接口中是没有具体实现的。
HttpServlet是Servlet的一个具体实现。HTTP Servlet 使用一个 HTML 表格来发送和接收数据。要创建一个 HTTP Servlet,请扩展 HttpServlet 类,该类是用专门的方法来处理 HTML 表格的 GenericServlet 的一个子类。 HTML 表单是由 FORM 和 /FORM 标记定义的。表单中典型地包含输入字段(如文本输入字段、复选框、单选按钮和选择列表)和用于提交数据的按钮。
每当一个客户请求一个HttpServlet 对象,该对象的service() 方法就要被调用,而且传递给这个方法一个"请求"(ServletRequest)对象和一个"响应"(ServletResponse)对象作为参数。在 HttpServlet 中已存在 service() 方法。缺省的服务功能是调用与 HTTP 请求的方法相应的 do 功能。例如, 如果 HTTP 请求方法为 GET,则缺省情况下就调用 doGet() 。Servlet 应该为 Servlet 支持的 HTTP 方法覆盖 do 功能。因为 HttpServlet.service() 方法会检查请求方法是否调用菜单跳转java代码了适当的处理方法,不必要覆盖 service() 方法。只需覆盖相应的 do 方法就可以菜单跳转java代码了。
Q2: 怎么在java窗口菜单程序中跳转到另一个页面???
import java.awt.*;
import java.awt.event.*;
public class report extends Frame implements ActionListener
{
Panel p=new Panel();
Panel test = new Panel();//声名2个新的面版
Panel test2 =new Panel();
Button btn=new Button("退出");
Label label1 = new Label("This is test panel");
Label label2 = new Label("This is test2 panel");
MenuBar mb=new MenuBar();
Menu m1=new Menu("报表统计");
MenuItem day=new MenuItem("日报表");
MenuItem month=new MenuItem("月报表");
report()
{
super("report");
setSize(350,200);
add("South",p);
p.add(btn);
btn.addActionListener(this);
test.setVisible(false);//设置test,test2的默认为不显示
test2.setVisible(false);
test.add(label1);
test2.add(label2);
m1.add(day);
m1.add(month);
day.addActionListener(this);
month.addActionListener(this);
mb.add(m1);
setMenuBar(mb);
show();
}
public static void main(String args[])
{
new report();
}
public void actionPerformed(ActionEvent e)
{
if (e.getActionCommand()=="日报表")
{
p.setVisible(false);
add("South",test);
test2.setVisible(false);
test.setVisible(true);//更改test面版为显示
test.setBackground(Color.CYAN);//设置面板颜色
test.setSize(400,400);
}
else if (e.getActionCommand()=="月报表")
{
p.setVisible(false);
test.setVisible(false);
add("South",test2);
test2.setSize(400,400);
test2.setVisible(true);
test2.setBackground(Color.RED);
}
}
}
Q3: Java单击确定按钮跳转到另一个界面的代码。调到另一个类的界面
public
void
actionPerformed(ActionEvent
e)
{
if(e.getSource()
==
button)
//或者e.getActionCommand().equals("确定')
{
Login
window
=
new
Login();
window.frame.setVisible(true);
}
}
这样就可以了。但是要在Login类中定义一个全局变量frame,即:private
JFrame
frame,并且记得初始化,frame
=new
JFrame();
菜单跳转java代码的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于java菜单栏中跳转、菜单跳转java代码的信息别忘了在本站进行查找喔。







