/**
* 菜单快捷键
*
* @time 12:40:40 PM
* @author retacn yue
* @Email zhenhuayue@sina.com
*/
public class Test_ShortcutTest extends Frame {
private static final long serialVersionUID = 1L;
double a, d, n, sum;
// 参数用于指定列数
TextField textField1 = new TextField(5),//
textField2 = new TextField(5),//
textField3 = new TextField(5),//
textField4 = new TextField(10);//
Label label1 = new Label("******计算等差/等比级数********"),//
label2 = new Label("输入初始值:"),//
label3 = new Label("输入公差/公比值:"),//
label4 = new Label("输出第几项"),//
label5 = new Label("输出总和:");//
/**
* 菜单快捷键
*
* 第二个参数是否需要同时按下shift键
*/
MenuShortcut menuShortcut1 = new MenuShortcut(KeyEvent.VK_A, true),//
menuShortcut2 = new MenuShortcut(KeyEvent.VK_S, false);
// 菜单栏
MenuBar bar = new MenuBar();
Menu menu = new Menu("级数");
MenuItem sz1 = new MenuItem("等差级数", menuShortcut1),//
sz2 = new MenuItem("等比级数", menuShortcut2);//
/**
* 构造器
*/
private Test_ShortcutTest() {
super("菜单快捷键测试");
setLayout(new FlowLayout());
setBackground(Color.orange);
menu.add(sz1);
menu.add(sz2);
bar.add(menu);
setMenuBar(bar);
add(label1);
add(label2);
add(textField1);
add(label3);
add(textField2);
add(label4);
add(textField3);
add(label5);
add(textField4);
setSize(200, 180);
setVisible(true);
addWindowListener(new koWindowListener());
sz1.addActionListener(new koActionListener());
sz2.addActionListener(new koActionListener());
}
/**
* 关闭窗体
*
* @time 1:22:40 PM
* @author retacn yue
* @Email zhenhuayue@sina.com
*/
class koWindowListener extends WindowAdapter {
@Override
public void windowClosing(WindowEvent e) {
e.getWindow().dispose();
System.exit(0);
}
}
/**
* 菜单单击监听
*
*/
class koActionListener implements ActionListener {
public void actionPerformed(ActionEvent e) {
a = new Double(textField1.getText()).doubleValue();
d = new Double(textField2.getText()).doubleValue();
n = new Double(textField3.getText()).doubleValue();
if (e.getSource() == sz1) {
textField4.setBackground(Color.yellow);
// 计算等差级数的总和
// 公式为:s=(a1+an)n/2
sum = (2 * a + (n - 1) * d) * n / 2;
} else if (e.getSource() == sz2) {
textField4.setBackground(Color.green);
/**
* 计算等比级数的总和
*
* 设比例因子为q 项数为n 首项为a1 和s=a1*(1-q^n)/(1-q)
*/
sum = a * (1 - Math.pow(d, n)) / (1 - d);
}
textField4.setText(String.valueOf(sum));
}
}
public static void main(String[] args) {
new Test_ShortcutTest();
}
}
分享到:
相关推荐
JavaFX+Jfoenix 学习笔记系列的JavaFX+Jfoenix 学习笔记(四)--MenuBar菜单栏的源码
通过xml文件配制Menubar实现动态填充菜单!再过itemClick事件获取下次子菜单
Python_tkinter_9_Menubar_菜单_(GUI_窗口_教学教程tutorial)
menuBar.7z菜单栏
qt5用代码实现界面创建,工具栏toolbar和菜单栏menubar。
FLex MenuBar的小例子,可以实现下拉菜单的效果,可直接拷贝使用
matlab开发-MenuBar。在图形窗口中的任何位置创建菜单栏
VC++的工具栏菜单,带源程序和DEMO 在VC7.0 VC7.1 VC8.0及ARX中调试通过
menubar rebar rightclick
.NET 较新版本中移除了系统样式的MenuBar,进而使用MenuStrip。该实例还原了系统菜单栏,更加美观。 (如无法打开,请在文件名后加上后缀“.zip”)
利用QML写的菜单样式,适合项目中用,定义了MenuItem和MenuBar的样式。实现是在Qt5.12.0中,应该是Qt5.10及以上都可以的。
这个功能MenuBar,允许用户在图中的任何地方创建菜单它用真正的菜单栏替换了 UIpanels 的 UIcontextmenu。 菜单栏(figure_handle)或菜单栏 鼠标悬停,可以通过以下方式启用窗口调整大小更新menubar('start',...
Private WithEvents MenuBar_MenuItem As MSForms.Label '菜单项 Private WithEvents WorkForm As MSForms.UserForm '工作窗口 Private WithEvents MenuBar As MSForms.Image '菜单栏 Private BackMenu_BackGroud As...
菜单栏通常包含一个或多个菜单,每个菜单包含若干个菜单项(`QAction`)。可以通过`QMenuBar`、`QMenu` 和 `QAction` 类来创建和管理菜单栏及其菜单项。 1. **创建一个菜单栏:** ```cpp QMenuBar *menuBar = ...
本案例是模仿饿了么,实现横向导航栏,可以参考用,也可以直接插入到项目中,接口方面使用的是mockJS模拟接口
Laravel开发-menubar 拉拉维尔的菜单栏建设者
TMenuBar component.
然后您可以使用codebox.menubar访问菜单栏: codebox . menubar . addMenu ( { caption : "My New Menu" , items : [ { caption : "My Command" , command : "mycomand" } , { type : "separator" } , {
用于替换 Visual C++ 使用开发人员 Studio 对象模型中的打开和添加文件到工程菜单项。解决这两个菜单项出错的问题。
一个工具栏菜单的源程序