Java中实现点击一个按钮出现一个新的页面且关闭当前页面
发布网友
发布时间:2022-05-03 00:08
我来回答
共6个回答
懂视网
时间:2022-04-20 07:51
最近在使用微信、支付宝、百度钱包实现网页支付,对支付成功将自动关闭页面,对于支付失败,将显示错误信息。当在错误页面的时候,点击返回
或者Android物理按键上一步的时候,将关闭页面。
在微信、支付宝、百度钱包中,他们对页面关闭进行了封装,传统的window.close()是无效的,必须要使用它们的js代码才能关闭。下面是三种移动app
的关闭方式:
WeixinJSBridge.call('closeWindow');//微信
AlipayJSBridge.call('closeWebview'); //支付宝
BLightApp.closeWindow();//百度钱包
通过浏览器的头判断是那种浏览器:
var ua = navigator.userAgent.toLowerCase();
f(ua.match(/MicroMessenger/i)=="micromessenger") {
alert("微信客户端");
} else if(ua.indexOf("alipay")!=-1){
alert("支付宝客户端");
}else if(ua.indexOf("baidu")!=-1){
alert("百度客户端");
}
对返回、上一页、后退进行监听,并对history中放入当前页地址:
$(function(){
pushHistory();
window.addEventListener("popstate", function(e) {
}, false);
function pushHistory() {
var state = {
title: "title",
url: "#"
};
window.history.pushState(state, "title", "#");
}
});
整个实现完整代码:
$(function(){
pushHistory();
window.addEventListener("popstate", function(e) {
pushHistory();
var ua = navigator.userAgent.toLowerCase();
if(ua.match(/MicroMessenger/i)=="micromessenger") {
WeixinJSBridge.call('closeWindow');
} else if(ua.indexOf("alipay")!=-1){
AlipayJSBridge.call('closeWebview');
}else if(ua.indexOf("baidu")!=-1){
BLightApp.closeWindow();
}
else{
window.close();
}
}, false);
function pushHistory() {
var state = {
title: "title",
url: "#"
};
window.history.pushState(state, "title", "#");
}
});
热心网友
时间:2022-04-20 04:59
采用以下代码即可:
JButton btn=new JButton(new AbstractAction("关闭并打开") {
@Override
public void actionPerformed(ActionEvent e) {
oldFrame.dispose();// 关闭并销毁,无需销毁可采用oldFrame.setVisible(false);
newFrame.setVisible(true);// 打开新窗口
}
});
热心网友
时间:2022-04-20 06:17
是Web工程吗?
你可以直接跳转到某页面,不用关闭,就在当前页面显示你要跳转的目标页面就行了啊!
或者写个js方法:function ct(){
window.open("2.jsp");//这个2.jsp是你要跳转到那个页面的页面url!
window.close();
}
在按钮的onclick="ct();"属性中调用这个方法!追问是GUI里面,添加事件。我们还没学后面那么多 - -
追答GUI我也不懂!
热心网友
时间:2022-04-20 07:51
在事件里添加
JFrame f=new JFrame();//不局限于JFrame,以你自己的窗口类名自行修改
this.dispose();//关闭当前窗口
就可以了
热心网友
时间:2022-04-20 09:43
public class NewJFrame extends javax.swing.JFrame {
/** Creates new form NewJFrame */
public NewJFrame() {
initComponents();
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private void initComponents() {
jPanel1 = new javax.swing.JPanel();
jScrollPane1 = new javax.swing.JScrollPane();
jTextArea1 = new javax.swing.JTextArea();
jScrollPane2 = new javax.swing.JScrollPane();
jTable1 = new javax.swing.JTable();
jScrollPane3 = new javax.swing.JScrollPane();
jTree1 = new javax.swing.JTree();
jButton1 = new javax.swing.JButton();
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jPanel1.setLayout(new java.awt.CardLayout());
jTextArea1.setColumns(20);
jTextArea1.setRows(5);
jScrollPane1.setViewportView(jTextArea1);
jPanel1.add(jScrollPane1, "card2");
jTable1.setModel(new javax.swing.table.DefaultTableModel(
new Object [][] {
{null, null, null, null},
{null, null, null, null},
{null, null, null, null},
{null, null, null, null}
},
new String [] {
"Title 1", "Title 2", "Title 3", "Title 4"
}
));
jScrollPane2.setViewportView(jTable1);
jPanel1.add(jScrollPane2, "card3");
jScrollPane3.setViewportView(jTree1);
jPanel1.add(jScrollPane3, "card4");
jButton1.setText("jButton1");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap(451, Short.MAX_VALUE)
.addComponent(jButton1)
.addGap(39, 39, 39))
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 563, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 264, Short.MAX_VALUE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
.addComponent(jButton1))
);
pack();
}// </editor-fold>
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
((CardLayout)this.jPanel1.getLayout()).next(jPanel1);
}
/**
* @param args the command line arguments
*/
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new NewJFrame().setVisible(true);
}
});
}
// Variables declaration - do not modify
private javax.swing.JButton jButton1;
private javax.swing.JPanel jPanel1;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JScrollPane jScrollPane2;
private javax.swing.JScrollPane jScrollPane3;
private javax.swing.JTable jTable1;
private javax.swing.JTextArea jTextArea1;
private javax.swing.JTree jTree1;
// End of variables declaration
}
热心网友
时间:2022-04-20 11:51
JSP中的onclick可以做到