jmenu

Java 图形化界面设计(GUI)实战练习(代码)

末鹿安然 提交于 2020-05-05 12:01:40
关于Java图形化界面设计,基础知识网上可搜,下面简单介绍一下重点概念,然后就由浅入深代码实例。 程序是为了方便用户使用的,Java引入图形化界面编程。 1.JFrame 是容器类 2.AWT 是抽象窗口组件工具包,是 Java 最早的用于编写图形节目应用程序的开发包。 3.Swing 是为了解决 AWT 存在的问题而新开发的包,它以 AWT 为基础的。 代码实例1: package com.zhouzhou; // 练习网格布局 import java.awt.* ; import javax.swing.* ; public class Demo9 extends JFrame { // 定义组件 int size = 9 ; JButton jbs[] = new JButton[size]; public static void main(String[] args) { // 创建实例 Demo9 de = new Demo9(); } // 构造函数 public Demo9() { // 创建组件 for ( int i = 0; i < size; i++ ) { jbs[i] = new JButton(String.valueOf(i)); } // 设置网格布局,这里只有前两个参数(行/列)3和3 的话,网格没有空隙 this .setLayout( new

201771010113 李婷华 《面向对象程序设计(java)》第九周总结

本小妞迷上赌 提交于 2020-05-01 21:57:54
一.理论知识部分 第六章 接口与内部类 1.内部类(innerclass)是定义在一个类内部的类。外层的类成为外部类(outerclass)。内部类主要用于事件处理。 2.使用内部类的原因有以下三个: (1)内部类方法可以访问该类定义所在的作用域中 的数据,包括私有数据。(2)内部类能够隐藏起来,不为同一包中的其他 类所见。(3) 想要定义一个回调函数且不想编写大量代码时, 使用匿名内部类比较便捷。 3.内部类可以直接访问外部类的成员,包括 private成员,但是内部类的成员却不能被外部类直接访问。 4. 在内部类对象保存了一个对外部类对象的引用, 当内部类的成员方法中访问某一变量时,如果在该方法和内部类中都未定义过这个变量,内部类中 对变量的引用会被传递给外部类 对象的引用。 5. 内部类并非只能在类内定义,也可以在程序块内 定义局部内部类。 例如,在方法中,甚至在for循环体内部。 6.局部内部类不能用public或private访问修饰符 进行声明,它的作用域被限定在声明这个局部类 的块中。 7. 若只创建类的一个对象,则不必为该类命名,这种类称为匿名内部类。 8. 由于匿名类没有类名,所以匿名类不能有构造器,取而代之的是将构造器参数传递给超类的构造器。 若匿名内部类实现接口时,则匿名内部类不能有任何构造参数。 如果构造参数的闭圆括号跟一个开花括号

Why isn't JMenu always on top?

守給你的承諾、 提交于 2020-01-13 06:44:05
问题 The JMenu behaves normally until a JButton is used to update a JTable on the JFrame. Then the JMenu is mostly hidden by a JPanel (see images below). Shouldn't the JMenu always be on top when it is selected? Why has it been pushed to the back? The code that updates the table on jButtonAddActionPerformed is. public class MyClass extends javax.swing.JFrame { private void jButtonAddActionPerformed(java.awt.event.ActionEvent evt) { DefaultTableModel model = (DefaultTableModel) jTable.getModel();

Custom JMenuItems in Java

不羁岁月 提交于 2020-01-10 10:34:01
问题 Would it be possible to create a custom JMenuItem that contains buttons? For example would it be possible to create a JMenuITem with an item similar to this: +----------------------------------------+ | JMenuItem [ Button | Button | Button ] | +----------------------------------------+ 回答1: I doubt there is an easy way to do this. You can do something like: JMenuItem item = new JMenuItem("Edit "); item.setLayout( new FlowLayout(FlowLayout.RIGHT, 5, 0) ); JButton copy = new JButton("Copy");

Custom JMenuItems in Java

ⅰ亾dé卋堺 提交于 2020-01-10 10:33:49
问题 Would it be possible to create a custom JMenuItem that contains buttons? For example would it be possible to create a JMenuITem with an item similar to this: +----------------------------------------+ | JMenuItem [ Button | Button | Button ] | +----------------------------------------+ 回答1: I doubt there is an easy way to do this. You can do something like: JMenuItem item = new JMenuItem("Edit "); item.setLayout( new FlowLayout(FlowLayout.RIGHT, 5, 0) ); JButton copy = new JButton("Copy");

How to prevent JMenuItem from closing Menu upon clicking the JMenuItem

一曲冷凌霜 提交于 2020-01-02 07:45:10
问题 How do I prevent a JMenuItem from closing the menu when the JMenuItem is clicked? The JMenuItem is enabled. So this is the scenario, I have 3 JMenuItems : JMenuItem: A, B, C ; C displays an integer X . A and B are used to increment or decrement X by a value of 1. If A or B is clicked, the default nature is that the menu will close upon click. I want to be able to repeatedly click A or B and have the menu remain up, and perform the associated 'action' upon each click. Thanks! 回答1: First, using

MenuListener Implementation, how to detect which JMenu was clicked?

丶灬走出姿态 提交于 2020-01-01 16:10:37
问题 If I have defined JMenu and JMenuBar like this: private JMenuBar jMenuBar; private JMenu jMenu1; jMenuBar = new JMenuBar(); jMenu1 = new JMenu(); jMenu1.setText("ABOUT"); //and here add a MenuListener so that i can detect when a menu is clicked: jMenu1.addMenuListener(this); jMenuBar.add(jMenu1); setJMenuBar(jMenuBar); //and here i implement the menulisteners public void menuSelected(MenuEvent e) { //my logic here } public void menuDeselected(MenuEvent e) {} public void menuCanceled(MenuEvent

Is it possible to make some items in the menu to fade in with 500 ms onset delay in Java?

泪湿孤枕 提交于 2019-12-25 07:18:28
问题 I have a JMenu of 16 JMenuItems, of which I want 3 items to be displayed upfront and the rest 13 items to fade in with a 500 ms delay. Is there a way to do this animation in Java? 回答1: This is not as easy as it sounds. Basically I originally thought "I'll attach a popup listener to the popup menu that the menu items are added to"...but apparently this doesn't work so well. The menu popup is built dynamically on demand. Makes sense, but it's still a pain. So instead, I've found that if I wait

How do I change the direction of JMenus in a JMenuBar

℡╲_俬逩灬. 提交于 2019-12-24 14:57:36
问题 When I create a menu in java GUI by using JMenuBar it puts all JMenu s from Left-to-right direction like this: I want to change it to Right-to-left like this: I want do this in an English OS, so suggestions of an Arabic or Right-to-Left solution aren't what I'm looking for. 回答1: You can use Component.applyComponentOrientation to change the orientation of the JMenuBar : import javax.swing.*; import java.awt.*; public class R_L_MenuBar_Demo { public static void main(String[] args){

Disable single ALT type to activate the menu

若如初见. 提交于 2019-12-24 06:17:08
问题 I'm trying to disable the default behavior of the ALT key in Windows Look and Feel when a JTextArea is focused and the frame has a JMenu installed. What happens by default is that the menu gets the keyboard focus and therefore you can't continue typing there. My first attempt was to capture single ALT presses by adding the key to the JTextArea InputMap: //Disable ALT key presses when the textarea is focused jta.getInputMap(javax.swing.JComponent.WHEN_FOCUSED).put(javax.swing.KeyStroke