「JAVA按键跳转」JAVA按键跳转页面后白屏
今天给各位分享JAVA按键跳转的知识,其中也会对JAVA按键跳转页面后白屏进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!
本文目录一览:
- 1、JAVA 点击按钮后跳到另一个界面
- 2、java怎么设置点击按钮跳转?
- 3、Java单击确定按钮跳转到另一个界面的代码。调到另一个类的界面
- 4、java程序中如何实现单击页面a中的按钮跳转到页面b
- 5、java按一下按钮就能跳到另一个界面怎么实现
JAVA 点击按钮后跳到另一个界面
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
public class Fre {
static JFrame frame = new JFrame();
public static void main(String[] args) {
//窗体大小
frame.setSize(200,200);
//按钮
JButton button =new JButton("点击我");
//在窗体上添加按钮
frame.add(button);
//显示窗体
frame.setVisible(true);
//添加点击事件监听器(你可以使用任何其他监听,看你想在什么情况下创建新的窗口了)
button.addActionListener(new ActionListener(){
//单击按钮执行的方法
public void actionPerformed(ActionEvent e) {
closeThis();
//创建新的窗口
JFrame frame = new JFrame("新窗口");
//设置在屏幕的位置
frame.setLocation(100,50);
// 窗体大小
frame.setSize(200,200);
// 显示窗体
frame.setVisible(true);
}
});
}
public static void closeThis(){
frame.dispose();
}
}
java怎么设置点击按钮跳转?
import javax.swing.*;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
//Math.random()*b.length
public class Test extends JFrame implements ActionListener{
private JLabel q;
private JLabel b;
private JTextField b2;
private JButton b1;
private String aa[] = { "公共的", "受保护的", "私有的" };
public Test() {
q = new JLabel();
b = new JLabel("请输入单词");
this.add(q);
this.setVisible(true);
this.setTitle("ii");
this.setSize(420, 320);
this.setLocation(200, 200);
this.setResizable(true);
this.setLayout(new FlowLayout());
this.add(b);
b2 = new JTextField(10);
this.add(b2);
b1 = new JButton("确定");
this.add(b1);
b1.addActionListener(this);
int p = (int) (Math.random() * aa.length);
String o = aa[p];
q.setText(o);
}
public static void main(String[] args) {
Test t = new Test();
}
@Override
public void actionPerformed(ActionEvent e) {
String h = "公共的";
if (h.equals(b2.getText())) {
int i = (int) (Math.random() * aa.length);
q.setText(aa[i]);
}
}
}
要给按钮加监听器
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程序中如何实现单击页面a中的按钮跳转到页面b
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‘”
java按一下按钮就能跳到另一个界面怎么实现
java实现的简单登录页面,从一个按钮点击后跳转的页面的jframe写法:
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class jb{
public static void main(String args[]){
JFrame f=new JFrame("点我跳转");
Container contentPane=f.getContentPane();
contentPane.setLayout(new GridLayout(1,2));
Icon icon=new ImageIcon("b.jpg");
JLabel label2=new JLabel("a",icon,JLabel.CENTER);
label2.setHorizontalTextPosition(JLabel.CENTER);
contentPane.setLayout(new FlowLayout( FlowLayout.CENTER,10,10));
JButton bb=new JButton("图片");
bb.addActionListener(new ActionListener(){
public void actionPerformed(ActionEvent e){
JFrame bf=new JFrame("新窗体");
Icon icon=new ImageIcon("enter.jpg");
JLabel label2=new JLabel(icon);
bf.getContentPane().add(label2);
bf.setSize(300,360);
bf.show();
}});
contentPane.add(label2);
contentPane.add(bb);
f.pack();
f.show();
}}
JAVA按键跳转的介绍就聊到这里吧,感谢你花时间阅读本站内容,更多关于JAVA按键跳转页面后白屏、JAVA按键跳转的信息别忘了在本站进行查找喔。
发布于:2022-11-27,除非注明,否则均为
原创文章,转载请注明出处。