java程序中如何实现单击页面a中的按钮跳转到页面b

java程序中如何实现单击页面a中的按钮跳转到页面b,第1张

java程序中的昌饥明jsp页面点击按钮跳转到页面b的耐告方式如下:

1.jsp页肢液面的方式如下:<a href="....b.jsp">跳转</a>

response.sendRedirect("b.jsp")

<jsp:forward page="b.jsp"/>

2.在swing里,给button加一个监听器,然后在监听事件中打开另一个页面。

在jsp或是静态网页里,onclick=“JavaScript:window.location=’xx‘”

假如有陵郑滚两个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()

}

}


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/8217932.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-14
下一篇 2023-04-14

发表评论

登录后才能评论

评论列表(0条)

保存