javax.swing.*!!!!!表嫌分少啊大侠!!!!!!

MikeDogSong 2003-12-12 10:03:31
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;

public class ActionSample extends JFrame {

// Swing Actions
private Action sampleAction;
private Action exitAction;

// ActionSample constructor
public ActionSample()
{
super( "Using Actions" );

// create AbstractAction subclass for sampleAction
sampleAction = new AbstractAction() {

public void actionPerformed( ActionEvent event )
{
// display message indicating sampleAction invoked
JOptionPane.showMessageDialog( ActionSample.this,
"The sampleAction was invoked" );

// enable exitAction and associated GUI components
exitAction.setEnabled( true );
}
};

// set Action name
sampleAction.putValue( Action.NAME, "Sample Action");

// set Action Icon
sampleAction.putValue( Action.SMALL_ICON, new ImageIcon(
getClass().getResource( "images/Help24.gif" ) ) );

// set Action short description (tooltip text)
/**************************************************************/
/* 我用vj++,在sun.com下了个swing1.1.1,安装后,在project属性里面
classpath活页中添加了c:\swing1.1.1\swingall.jar,然后编译,可是提示
下面的Action.MNEMONIC_KEY没有定义!!!怎么办?怎么办?很着急,谢谢了
/*************************************************************/
sampleAction.putValue( Action.SHORT_DESCRIPTION,
"A Sample Action" );

// set Action mnemonic key
sampleAction.putValue( Action.MNEMONIC_KEY,
new Integer( 'S' ) );

// create AbstractAction subclass for exitAction
exitAction = new AbstractAction() {

public void actionPerformed( ActionEvent event )
{
// display message indicating exitAction invoked
JOptionPane.showMessageDialog( ActionSample.this,
"The exitAction was invoked" );
System.exit( 0 );
}
};

// set Action name
exitAction.putValue( Action.NAME, "Exit" );

// set Action icon
exitAction.putValue( Action.SMALL_ICON, new ImageIcon(
getClass().getResource( "images/EXIT.gif" ) ) );

// set Action short description (tooltip text)
exitAction.putValue( Action.SHORT_DESCRIPTION,
"Exit Application" );

// set Action mnemonic key
exitAction.putValue( Action.MNEMONIC_KEY,
new Integer( 'x' ) );

// disable exitAction and associated GUI components
exitAction.setEnabled( false );

// create File menu
JMenu fileMenu = new JMenu( "File" );

// add sampleAction and exitAction to File menu to
// create a JMenuItem for each Action
fileMenu.add( sampleAction );
fileMenu.add( exitAction );

fileMenu.setMnemonic( 'F' );

// create JMenuBar and add File menu
JMenuBar menuBar = new JMenuBar();
menuBar.add( fileMenu );
setJMenuBar( menuBar );

// create JToolBar
JToolBar toolBar = new JToolBar();

// add sampleAction and exitAction to JToolBar to create
// JButtons for each Action
toolBar.add( sampleAction );
toolBar.add( exitAction );

// create JButton and set its Action to sampleAction
JButton sampleButton = new JButton();
sampleButton.setAction( sampleAction );

// create JButton and set its Action to exitAction
JButton exitButton = new JButton( exitAction );

// lay out JButtons in JPanel
JPanel buttonPanel = new JPanel();
buttonPanel.add( sampleButton );
buttonPanel.add( exitButton );

// add toolBar and buttonPanel to JFrame's content pane
Container container = getContentPane();
container.add( toolBar, BorderLayout.NORTH );
container.add( buttonPanel, BorderLayout.CENTER );
}

// execute application
public static void main( String args[] )
{
ActionSample sample = new ActionSample();
sample.setDefaultCloseOperation( EXIT_ON_CLOSE );
sample.pack();
sample.setVisible( true );
}
}
...全文
19 1 打赏 收藏 举报
写回复
1 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
MikeDogSong 2003-12-12
swing1.1.1按装路径绝对没错!!!
  • 打赏
  • 举报
回复
相关推荐
发帖
Java SE
加入

6.2w+

社区成员

Java 2 Standard Edition
申请成为版主
帖子事件
创建了帖子
2003-12-12 10:03
社区公告
暂无公告