JAVA 点击按钮后跳到另一个界面

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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();

参考技术A 1、在jsp页面定义一个button按钮
2、给按钮一个onclick事件
3、定义onclick事件的处理函数
4、在处理函数中利用window.location.href跳转到指定的页面
示例:
<input type="button" id="mybutton" value="跳转测试" onclick="goPage();"/>
js:
function goPage()
window.location.href="指定的url";
参考技术B 一看就知道是程序初哥问的问题。

Android如何做类似淘宝那样,把按钮固定底部,点击按钮跳到别的界面,底部按钮不会改变呢?

下面按钮标签不改变,固定住。点下面的按钮标签能显示别的页面。 Android新手,求前辈指导!

参考技术A fragment知道吧
创建一个activity,布局是
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/activity_bg_default"
android:orientation="vertical">

<Fragment
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@color/material_text_color_black_divider" />

<RadioGroup
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:gravity="center_vertical"
android:orientation="horizontal"
android:paddingBottom="7dp">

<RadioButton
android:id="@+id/bottom_bar1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:tag="0"
android:button="@null"
android:checked="true"
android:drawableBottom="@drawable/main_bottom_btn1" />

<RadioButton
android:id="@+id/bottom_bar2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:button="@null"
android:tag="1"
android:drawableBottom="@drawable/main_bottom_btn2" />

<ImageButton
android:id="@+id/bottom_center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginTop="5dp"
android:layout_weight="1"
android:background="@color/activity_bg_default"
android:src="@drawable/ic_main_center" />

<RadioButton
android:id="@+id/bottom_bar3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:tag="2"
android:button="@null"
android:drawableBottom="@drawable/main_bottom_btn3" />

<RadioButton
android:id="@+id/bottom_bar4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:button="@null"
android:tag="3"
android:drawableBottom="@drawable/main_bottom_btn4" />

</RadioGroup>
</LinearLayout>

然后会用 就创建四个fragment,在activity利用hide和show的特性对应radiobutton来做点击切换。
不会用立刻去百度,给你上一课,不会的要百度。提问太慢了追问

谢谢前辈

本回答被提问者和网友采纳

以上是关于JAVA 点击按钮后跳到另一个界面的主要内容,如果未能解决你的问题,请参考以下文章

怎么用eclipse做一个界面点击按钮就可以跳转到另一个界面的代码

java中如何点击按钮跳转到网页(在浏览器中打开)

如何在同一个tomcat中执行两个项目,一个项目中有个按钮,点击跳到另一个项目中的主页面

Xaml Controls Gallery 的五个没有用的控件

AndroidButton之实现点击按钮跳转到另一个界面

wpf怎么new一个新窗口(就是点击按钮后跳到一个新窗口,就像页面跳转那样)