java 状态栏_Java基础之扩展GUI——添加状态栏(Sketcher 1 with a status bar)

该博客介绍了如何使用Java Swing库扩展GUI,创建一个名为Sketcher的应用程序,并添加状态栏。文章详细展示了SketcherFrame类的实现,包括构造函数、菜单栏的创建、文件菜单项的行动、元素类型菜单、颜色菜单以及工具栏按钮的添加。通过这个例子,读者可以学习到如何在Java应用程序中添加和管理菜单、工具栏以及状态栏。
摘要由CSDN通过智能技术生成

1 //Frame for the Sketcher application

2 import javax.swing.*;3 import javax.swing.border.*;4 import java.awt.event.*;5 import java.awt.*;6

7 import static java.awt.event.InputEvent.*;8 import static java.awt.Color.*;9 import static Constants.SketcherConstants.*;10 import static javax.swing.Action.*;11

12 @SuppressWarnings("serial")13 public class SketcherFrame extendsJFrame {14 //Constructor

15 publicSketcherFrame(String title, Sketcher theApp) {16 setTitle(title); //Set the window title

17 this.theApp = theApp; //Save app. object reference

18 setJMenuBar(menuBar); //Add the menu bar to the window

19 setDefaultCloseOperation(EXIT_ON_CLOSE); //Default is exit the application

20

21 createFileMenu(); //Create the File menu

22 createElementMenu(); //Create the element menu

23 createColorMenu(); //Create the element menu

24 createToolbar();25 toolBar.setRollover(true);26 getContentPane().add(toolBar, BorderLayout.NORTH); //Add the toolbar

27 getContentPane().add(statusBar, BorderLayout.SOUTH); //Add the statusbar

28 }29

30 //Create File menu item actions

31 private voidcreateFileMenuActions() {32 newAction = new FileAction("New", 'N', CTRL_DOWN_MASK);33 openAction = new FileAction("Open", 'O', CTRL_DOWN_MASK);34 closeAction = new FileAction("Close");35 saveAction = new FileAction("Save", 'S', CTRL_DOWN_MASK);36 saveAsAction = new FileAction("Save As...");37 printAction = new FileAction("Print", 'P', CTRL_DOWN_MASK);38 exitAction = new FileAction("Exit", 'X', CTRL_DOWN_MASK);39

40 //Initialize the array

41 FileAction[] actions ={openAction, closeAction, saveAction, saveAsAction, printAction, exitAction};42 fileActions =actions;43

44 //Add toolbar icons

45 newAction.putValue(LARGE_ICON_KEY, NEW24);46 openAction.putValue(LARGE_ICON_KEY, OPEN24);47 saveAction.putValue(LARGE_ICON_KEY, SAVE24);48 saveAsAction.putValue(LARGE_ICON_KEY, SAVEAS24);49 printAction.putValue(LARGE_ICON_KEY, PRINT24);50

51 //Add menu item icons

52 newAction.putValue(SMALL_ICON, NEW16);53 openAction.putValue(SMALL_ICON, OPEN16);54 saveAction.putValue(SMALL_ICON, SAVE16);55 saveAsAction.putValue(SMALL_ICON,SAVEAS16);56 printAction.putValue(SMALL_ICON, PRINT16);57

58 //Add tooltip text

59 newAction.putValue(SHORT_DESCRIPTION, "Create a new sketch");60 openAction.putValue(SHORT_DESCRIPTION, "Read a sketch from a file");61 closeAction.putValue(SHORT_DESCR

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值