-
JAVA实现选择按钮分别弹出_Java点击按钮弹出窗口(两种按钮)
2021-03-10 05:06:47import java.awt.Button;import java.awt.Frame;import java.awt.Panel;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.swing.JButton;import javax.swing.JFrame;@Suppress...import java.awt.Button;
import java.awt.Frame;
import java.awt.Panel;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
@SuppressWarnings("serial")
public class Login extends Frame{
public Login(String str){
super(str);
}
static Login fr = new Login("测试Panel");
public static void main(String[] args){
fr.setSize(500, 500);
fr.setLocation(500, 300);
fr.setBackground(null);
fr.setLayout(null);
Button button = new Button("点击我");
button.setSize(50, 25);
//button.setBorderPainted(false);
button.setLocation(50, 50);
button.addActionListener(new ActionListener(){
//单击按钮执行的方法
public void actionPerformed(ActionEvent e) {
closeThis();
//创建新的窗口
JFrame frame = new JFrame("新窗口");
//设置在屏幕的位置
frame.setLocation(100,50);
//窗体大小
frame.setSize(500,500);
//显示窗体
frame.setVisible(true);
}
});
JButton button1 = new JButton("点");
button1.setSize(50, 25);
button1.setBackground(null);
button1.setBorderPainted(false);
button1.setLocation(50,80 );
button1.addActionListener(new ActionListener(){
//单击按钮执行的方法
public void actionPerformed(ActionEvent e) {
closeThis();
//创建新的窗口
JFrame frame1 = new JFrame("新窗口");
//设置在屏幕的位置
frame1.setLocation(100,50);
//窗体大小
frame1.setSize(200,200);
JButton button2 = new JButton("点击我");
button2.setSize(50, 25);
button2.setBorderPainted(false);
button2.setLocation(50,80 );
button2.addActionListener(new ActionListener(){
//单击按钮执行的方法
public void actionPerformed(ActionEvent e) {
closeThis();
//创建新的窗口
JFrame frame = new JFrame("新窗口");
//设置在屏幕的位置
frame.setLocation(200,50);
//窗体大小
frame.setSize(200,200);
//显示窗体
frame.setVisible(true);
}
});
Panel pan = new Panel();
pan.setSize(100, 100);
frame1.add(button2);
frame1.add(pan);
//显示窗体
frame1.setVisible(true);
}
});
fr.add(button);
fr.add(button1);
fr.setVisible(true);
}
public static void closeThis(){
fr.dispose();
}
}
-
java弹出子窗口_java实现点击按钮事件弹出子窗口
2021-03-04 04:16:07本文实例为大家分享了java实现点击按钮事件弹出子窗口的具体代码,供大家参考,具体内容如下要求:1、在父窗口中添加一个按钮2、点击按钮弹出子窗口注意:这是JDK1.7版本在JDK1.7之前,JFrame是不能直接添加子窗口的...本文实例为大家分享了java实现点击按钮事件弹出子窗口的具体代码,供大家参考,具体内容如下
要求:
1、在父窗口中添加一个按钮
2、点击按钮弹出子窗口
注意:这是JDK1.7版本
在JDK1.7之前,JFrame是不能直接添加子窗口的,要先将JInternalFrame添加到JDesktopPane中,再将JDesktopPane添加到父窗口内,完成这个操作。
(一)建立父类JFrame
package com.java.view;
import java.awt.BorderLayout;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JDesktopPane;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JMenuBar;
public class Testfrm extends JFrame {
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Testfrm frame = new Testfrm();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public Testfrm() {
setTitle("\u7236\u7A97\u53E3");//标题
setBounds(400, 300, 800, 600);//父窗口的坐标和大小
getContentPane().setLayout(null);//自由布局
JButton bt = new JButton("\u6309\u94AE");//按钮的变量名为bt
bt.setBounds(0, 0, 93, 23);//按钮的位置坐标和大小
getContentPane().add(bt);//按钮添加到窗口中
bt.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Testinterfrm testinterfrm=new Testinterfrm();//新建子窗口对象
testinterfrm.setVisible(true);//子窗口可见
getContentPane().add(testinterfrm);//子窗口添加到父窗口中
}
});
}
}
(二)建立子类JInternalFrame
package com.java.view;
import java.awt.BorderLayout;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JDesktopPane;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JMenuBar;
public class Testfrm extends JFrame {
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Testfrm frame = new Testfrm();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public Testfrm() {
setTitle("\u7236\u7A97\u53E3");//标题
setBounds(400, 300, 800, 600);//父窗口的坐标和大小
getContentPane().setLayout(null);//自由布局
JButton bt = new JButton("\u6309\u94AE");//按钮的变量名为bt
bt.setBounds(0, 0, 93, 23);//按钮的位置坐标和大小
getContentPane().add(bt);//按钮添加到窗口中
bt.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Testinterfrm testinterfrm=new Testinterfrm();//新建子窗口对象
testinterfrm.setVisible(true);//子窗口可见
getContentPane().add(testinterfrm);//子窗口添加到父窗口中
}
});
}
}
运行结果:
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持谷谷点程序。
-
java按钮点击弹出_Java弹出按钮
2021-03-16 00:37:31注意:您可能必须编译并运行我的示例才能完全理解我的问题....因此,该行为类似于JComboBox,不同之处在于弹出窗口可以包含任意组件.下面的代码是如何创建控件的示例(除了它将在其自己的类中,例如JPopupTo...注意:您可能必须编译并运行我的示例才能完全理解我的问题.如果不是犹太洁食,我事先表示歉意.
我试图创建一个基于JToggleButton和JPopupMenu的Swing控件.
如果弹出菜单可见,则选择切换按钮;如果弹出菜单不可见,则取消选择切换按钮.因此,该行为类似于JComboBox,不同之处在于弹出窗口可以包含任意组件.
下面的代码是如何创建控件的示例(除了它将在其自己的类中,例如JPopupToggleButton之类).不幸的是,它在不同的外观和感觉下表现出不同的行为(我已经用Metal和Nimbus对其进行了测试).
此处发布的代码在Metal中表现出预期的效果,但在Nimbus中却表现不佳.使用Nimbus时,只需反复单击切换按钮即可显示和隐藏弹出窗口,您将明白我的意思.
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.MouseInfo;
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
import javax.swing.event.PopupMenuEvent;
import javax.swing.event.PopupMenuListener;
public class PopupButtonExample extends JFrame
{
public static void main( String[] args )
{
java.awt.EventQueue.invokeLater( new Runnable()
{
@Override
public void run()
{
PopupButtonExample example = new PopupButtonExample();
example.setDefaultCloseOperation( JFrame.EXIT_ON_CLOSE );
example.setVisible( true );
}
});
}
public PopupButtonExample()
{
super( "Components in Popup" );
JPanel popupPanel = new JPanel();
popupPanel.setLayout( new BorderLayout() );
popupPanel.add( new JLabel( "This popup has components" ),
BorderLayout.NORTH );
popupPanel.add( new JTextArea( "Some text", 15, 20 ),
BorderLayout.CENTER );
popupPanel.add( new JSlider(), BorderLayout.SOUTH );
final JPopupMenu popupMenu = new JPopupMenu();
popupMenu.add( popupPanel );
final JToggleButton popupButton = new JToggleButton( "Show Popup" );
popupButton.addActionListener( new ActionListener()
{
@Override
public void actionPerformed(ActionEvent e)
{
if( popupButton.isSelected() )
popupMenu.show( popupButton, 0, popupButton.getHeight() );
}
});
popupMenu.addPopupMenuListener( new PopupMenuListener()
{
@Override
public void popupMenuWillBecomeVisible(PopupMenuEvent pme) {}
@Override
public void popupMenuCanceled(PopupMenuEvent pme) {}
@Override
public void popupMenuWillBecomeInvisible(PopupMenuEvent pme) {
Point mouseLoc = MouseInfo.getPointerInfo().getLocation();
Point componentLoc = popupButton.getLocationOnScreen();
mouseLoc.x -= componentLoc.x;
mouseLoc.y -= componentLoc.y;
if( !popupButton.contains( mouseLoc ) )
popupButton.setSelected( false );
}
});
JPanel toolBarPanel = new JPanel();
toolBarPanel.add( popupButton );
JToolBar toolBar = new JToolBar();
toolBar.add( toolBarPanel );
setLayout( new BorderLayout() );
add( toolBar, BorderLayout.PAGE_START );
setPreferredSize( new Dimension( 640, 480 ) );
pack();
}
}
区分以下几行可使代码在Nimbus中表现出预期的效果,但在Metal中却表现出预期.同样,只要继续单击切换按钮,即可查看我的意思.
// Point mouseLoc = MouseInfo.getPointerInfo().getLocation();
// Point componentLoc = popupButton.getLocationOnScreen();
// mouseLoc.x -= componentLoc.x;
// mouseLoc.y -= componentLoc.y;
// if( !popupButton.contains( mouseLoc ) )
所以这是我的两个问题:
(1)在Nimbus中,为什么隐藏弹出面板的单击没有像Metal那样传递到切换按钮?
(2)如何解决这个问题,使其在所有外观上都可以使用?
-
java 如何实现弹出一个窗口锁定父窗口_java实现点击按钮事件弹出子窗口
2021-02-28 14:08:18本文实例为大家分享了java实现点击按钮事件弹出子窗口的具体代码,供大家参考,具体内容如下要求:1、在父窗口中添加一个按钮2、点击按钮弹出子窗口注意:这是JDK1.7版本在JDK1.7之前,JFrame是不能直接添加子窗口的...本文实例为大家分享了java实现点击按钮事件弹出子窗口的具体代码,供大家参考,具体内容如下
要求:
1、在父窗口中添加一个按钮
2、点击按钮弹出子窗口
注意:这是JDK1.7版本
在JDK1.7之前,JFrame是不能直接添加子窗口的,要先将JInternalFrame添加到JDesktopPane中,再将JDesktopPane添加到父窗口内,完成这个操作。
(一)建立父类JFrame
package com.java.view;
import java.awt.BorderLayout;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JDesktopPane;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JMenuBar;
public class Testfrm extends JFrame {
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Testfrm frame = new Testfrm();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public Testfrm() {
setTitle("\u7236\u7A97\u53E3");//标题
setBounds(400, 300, 800, 600);//父窗口的坐标和大小
getContentPane().setLayout(null);//自由布局
JButton bt = new JButton("\u6309\u94AE");//按钮的变量名为bt
bt.setBounds(0, 0, 93, 23);//按钮的位置坐标和大小
getContentPane().add(bt);//按钮添加到窗口中
bt.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Testinterfrm testinterfrm=new Testinterfrm();//新建子窗口对象
testinterfrm.setVisible(true);//子窗口可见
getContentPane().add(testinterfrm);//子窗口添加到父窗口中
}
});
}
}
(二)建立子类JInternalFrame
package com.java.view;
import java.awt.BorderLayout;
import java.awt.EventQueue;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JDesktopPane;
import javax.swing.JButton;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import javax.swing.JMenuBar;
public class Testfrm extends JFrame {
/**
* Launch the application.
*/
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
public void run() {
try {
Testfrm frame = new Testfrm();
frame.setVisible(true);
} catch (Exception e) {
e.printStackTrace();
}
}
});
}
/**
* Create the frame.
*/
public Testfrm() {
setTitle("\u7236\u7A97\u53E3");//标题
setBounds(400, 300, 800, 600);//父窗口的坐标和大小
getContentPane().setLayout(null);//自由布局
JButton bt = new JButton("\u6309\u94AE");//按钮的变量名为bt
bt.setBounds(0, 0, 93, 23);//按钮的位置坐标和大小
getContentPane().add(bt);//按钮添加到窗口中
bt.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Testinterfrm testinterfrm=new Testinterfrm();//新建子窗口对象
testinterfrm.setVisible(true);//子窗口可见
getContentPane().add(testinterfrm);//子窗口添加到父窗口中
}
});
}
}
运行结果:
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持脚本之家。
-
java实现点击按钮事件弹出子窗口
2020-08-25 19:03:10主要为大家详细介绍了java实现点击按钮事件弹出子窗口,具有一定的参考价值,感兴趣的小伙伴们可以参考一下 -
java 界面自动弹出_java程序点击弹出窗口
2021-03-09 00:23:34我有下面的两个小程序我点击第一个的查询按钮时会弹出第二个窗口,但是我第二个窗口弹出来以后第一个窗口也可以操作,我想让第二个窗口弹出来以后第一个窗口不能被操作,关闭第二个窗...我有下面的两个小程序我点击... -
invoke 按钮点击_java实现点击按钮事件弹出子窗口
2021-01-14 07:14:58本文实例为大家分享了java实现点击按钮事件弹出子窗口的具体代码,供大家参考,具体内容如下要求:1、在父窗口中添加一个按钮2、点击按钮弹出子窗口注意:这是JDK1.7版本在JDK1.7之前,JFrame是不能直接添加子窗口的... -
java子窗口_java实现点击按钮事件弹出子窗口
2021-02-12 13:50:20本文实例为大家分享了java实现点击按钮事件弹出子窗口的具体代码,供大家参考,具体内容如下要求:1、在父窗口中添加一个按钮2、点击按钮弹出子窗口注意:这是JDK1.7版本在JDK1.7之前,JFrame是不能直接添加子窗口的... -
java弹窗点击事件_java实现点击按钮事件弹出子窗口
2021-03-10 08:16:34本文实例为大家分享了java实现点击按钮事件弹出子窗口的具体代码,供大家参考,具体内容如下要求:1、在父窗口中添加一个按钮2、点击按钮弹出子窗口注意:这是JDK1.7版本在JDK1.7之前,JFrame是不能直接添加子窗口的... -
java窗口添加按钮事件_java实现点击按钮事件弹出子窗口|chu
2021-02-26 13:07:25本文实例为大家分享了java实现点击按钮事件弹出子窗口的具体代码,供大家参考,具体内容如下要求:1、在父窗口中添加一个按钮2、点击按钮弹出子窗口注意:这是JDK1.7版本在JDK1.7之前,JFrame是不能直接添加子窗口的... -
Java点击按钮弹出窗口(两种按钮)
2014-12-11 10:50:45import java.awt.Button; import java.awt.Frame; import java.awt.Panel; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import javax.swing.JButton; import javax.swing.JFrame; -
java按钮新窗口_java实现点击按钮弹出新窗体功能
2021-03-08 02:46:43本文实例为大家分享了Java实现点击按钮弹出新窗体的功能,旧窗体不进行操作分析:对于自定义窗体来说,最简单直接的做法就是让新窗体继承javax.swing.JDialog(对话框属于顶级窗口,跟JFrame同级),在创建该窗体后... -
java按钮新建窗口_java实现点击按钮弹出新窗体功能
2021-02-26 18:51:37本文实例为大家分享了Java实现点击按钮弹出新窗体的功能,旧窗体不进行操作分析:对于自定义窗体来说,最简单直接的做法就是让新窗体继承javax.swing.JDialog(对话框属于顶级窗口,跟JFrame同级),在创建该窗体后... -
java窗口添加按钮事件_JAVA中点击按钮事件弹出子窗口:JInternalFrame的使用
2021-03-01 10:50:42要求:1、在父窗口中添加一个按钮2、点击按钮弹出子窗口注意:这是JDK1.7版本在JDK1.7之前,JFrame是不能直接添加子窗口的,要先将JInternalFrame添加到 JDesktopPane 中,再将JDesktopPane添加到父窗口内,完成这个... -
java窗口按钮_java实现点击按钮弹出新窗体功能
2021-02-12 13:31:04本文实例为大家分享了Java实现点击按钮弹出新窗体的功能,旧窗体不进行操作分析:对于自定义窗体来说,最简单直接的做法就是让新窗体继承javax.swing.JDialog(对话框属于顶级窗口,跟JFrame同级),在创建该窗体后... -
JAVA中点击按钮事件弹出子窗口:JInternalFrame的使用
2017-03-08 16:49:502、点击按钮弹出子窗口 注意:这是JDK1.7版本 在JDK1.7之前,JFrame是不能直接添加子窗口的,要先将JInternalFrame添加到 JDesktopPane 中, 再将JDesktopPane 添加到父窗口内,完成这个操作。 (一)建立父类... -
java点击按钮弹出下拉框_自定义下拉列表与PopupWindow的使用(弹出窗口)
2021-03-15 18:18:40importjava.util.ArrayList;importandroid.os.Bundle;importandroid.app.Activity;importandroid.text.TextUtils;importandroid.view.Menu;importandroid.view.View;importandroid.view.ViewGroup;importandroid.wid... -
Java点击按钮后弹出新窗口,关闭新窗口后如何返回到原来的窗口?
2015-07-21 09:54:54如题,现在设计一个界面,里面有一个按钮,增加ActionListener事件,点击按钮后弹出一个新的窗口,里面有更详细的信息。现在将新窗口关闭,想返回到原来的旧窗口。菜鸟一枚,请前辈指点迷津... -
java点击按钮事件,弹出窗口出错 求帮助啊0.0
2017-05-07 06:04:05弹出窗口后应该是这样的: 但是结果是这样的: -
java 悬浮 小 窗口代码_点击按钮弹出悬浮窗口的小例子
2021-03-11 16:47:51// 调整悬浮窗口至右侧中间 // 以屏幕左上角为原点,设置x、y初始值 wmParams.x = 0; wmParams.y = 0; // 设置悬浮窗口长宽数据 wmParams.width = WindowManager.LayoutParams.WRAP_CONTENT; wmParams.height =... -
java有没有自定义好的按钮_javafx中点击按钮弹出自定义窗口如何实现
2021-03-14 16:26:30自定义弹窗,主要是获取控件元素的windows对象,窗口内容可以用FXML配置,如下:/*** 按钮事件:启动子窗口* @throws IOException*/@FXMLprivate void onLogin(ActionEvent event) throws IOException {Stage stage=... -
java怎么点击跳出设计的窗口_java gui编程教程java swing 编程中,如何实现点击按钮弹出新的窗口?...
2021-03-16 16:56:25java gui编程教程java swing 编程中,如何实现点击按钮弹出新的窗口???import java.awt.Button;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import javax.swing.JFrame;public ... -
java setmnemonic_java实现点击按钮弹出新窗体功能
2021-03-21 08:53:23本文实例为大家分享了Java实现点击按钮弹出新窗体的功能,旧窗体不进行操作分析:对于自定义窗体来说,最简单直接的做法就是让新窗体继承javax.swing.JDialog(对话框属于顶级窗口,跟JFrame同级),在创建该窗体后... -
java图形化界面点击button怎么弹出窗口_你好,请问怎么在JAVA的图形界面中点击按钮只能弹出一个子窗体...
2021-03-13 10:26:46给你一段我自己用swing写的mdi(多文档用户界面)的代码,仅供参考:package ...import java.awt.awtevent;import java.awt.borderlayout;import java.awt.dimension;import java.awt.flowlayout;import jav... -
java swing中点击按钮后弹出JFrame窗口,关闭弹出的窗口,程序都关了的解决方案
2013-11-22 20:56:40给Frame添加一个窗口监听,在实现的windowClosing方法中调用dipose() frame.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { -
java按下按钮打开新界面_java实现点击按钮弹出新窗体功能|chu
2021-03-08 10:16:54本文实例为大家分享了Java实现点击按钮弹出新窗体的功能,旧窗体不进行操作分析:对于自定义窗体来说,最简单直接的做法就是让新窗体继承javax.swing.JDialog(对话框属于顶级窗口,跟JFrame同级),在创建该窗体后... -
java swing 窗口_java swing 编程中,如何实现点击按钮弹出新的窗口???
2021-02-12 13:30:40展开全部其实32313133353236313431303231363533e78988e69d8331333335313762是内部类的运用,我附上了程序源码和运行结果...importjava.awt.event.ActionListener;importjava.awt.event.ActionEvent;publicclasspopu...