本文整理汇总了Java中java.awt.Button.addActionListener方法的典型用法代码示例。如果您正苦于以下问题:Java Button.addActionListener方法的具体用法?Java Button.addActionListener怎么用?Java Button.addActionListener使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类java.awt.Button
的用法示例。
在下文中一共展示了Button.addActionListener方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import java.awt.Button; //导入方法依赖的package包/类
public static void main(final String[] args) throws AWTException {
final bug7097771 frame = new bug7097771();
frame.setSize(300, 300);
frame.setLocationRelativeTo(null);
final Button button = new Button();
button.addActionListener(frame);
frame.add(button);
frame.setVisible(true);
sleep();
frame.setEnabled(false);
button.setEnabled(false);
button.setEnabled(true);
sleep();
Util.clickOnComp(button, new Robot());
sleep();
frame.dispose();
if (action) {
throw new RuntimeException("Button is not disabled.");
}
}
示例2: TestDialog
import java.awt.Button; //导入方法依赖的package包/类
public TestDialog(Frame frame, String name) {
super(frame, name);
int scrollBoth = TextArea.SCROLLBARS_BOTH;
instructionsText = new TextArea("", 15, maxStringLength, scrollBoth);
add("North", instructionsText);
messageText = new TextArea("", 5, maxStringLength, scrollBoth);
add("Center", messageText);
buttonP = new Panel();
passB = new Button("pass");
passB.setActionCommand("pass");
passB.addActionListener(this);
buttonP.add("East", passB);
failB = new Button("Fail");
failB.setActionCommand("fail");
failB.addActionListener(this);
buttonP.add("West", failB);
add("South", buttonP);
pack();
setVisible(true);
}
示例3: main
import java.awt.Button; //导入方法依赖的package包/类
public static void main(final String[] args) throws AWTException {
final bug7097771 frame = new bug7097771();
frame.setSize(300, 300);
frame.setLocationRelativeTo(null);
final Button button = new Button();
button.addActionListener(frame);
frame.add(button);
frame.setVisible(true);
Robot robot = new Robot();
sleep(robot);
frame.setEnabled(false);
button.setEnabled(false);
button.setEnabled(true);
sleep(robot);
Util.clickOnComp(button, robot);
sleep(robot);
frame.dispose();
if (action) {
throw new RuntimeException("Button is not disabled.");
}
}
示例4: init
import java.awt.Button; //导入方法依赖的package包/类
private void init(Component parent, String title, String message,
String buttonText) {
Panel p = new Panel();
add("Center", new Label(message));
Button btn = new Button(buttonText);
btn.addActionListener(this);
p.add(btn);
add("South", p);
pack();
Dimension dDim = getSize();
if (parent != null) {
Rectangle fRect = parent.getBounds();
setLocation(fRect.x + ((fRect.width - dDim.width) / 2),
fRect.y + ((fRect.height - dDim.height) / 2));
}
}
示例5: TestDialog
import java.awt.Button; //导入方法依赖的package包/类
public TestDialog( Frame frame, String name )
{
super( frame, name );
int scrollBoth = TextArea.SCROLLBARS_BOTH;
instructionsText = new TextArea( "", 15, maxStringLength, scrollBoth );
add( "North", instructionsText );
messageText = new TextArea( "", 5, maxStringLength, scrollBoth );
add("Center", messageText);
passB = new Button( "pass" );
passB.setActionCommand( "pass" );
passB.addActionListener( this );
buttonP.add( "East", passB );
failB = new Button( "fail" );
failB.setActionCommand( "fail" );
failB.addActionListener( this );
buttonP.add( "West", failB );
add( "South", buttonP );
pack();
show();
}
示例6: initTestWindow
import java.awt.Button; //导入方法依赖的package包/类
public static void initTestWindow() {
mainFrame = new Frame();
p1 = new Panel();
mainFrame.setTitle("TestWindow");
mainFrame.setBounds(700, 10, 400, 100);
tf = new TextField(20);
tf.select(0, 10);
bt = new Button("Disable textfield");
p1.add(tf);
p1.add(bt);
mainFrame.add(p1);
bt.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent ae) {
tf.setEditable(false);
}
});
mainFrame.setVisible(true);
}
示例7: executeTest
import java.awt.Button; //导入方法依赖的package包/类
private void executeTest() {
GraphicsDevice defDev = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice();
int x = 0;
Frame f = null;
for (x = 0; x < gd.length; x ++) {
if (gd[x] != defDev) {
secFrame = new Frame("Screen " + x + " - secondary", gd[x].getDefaultConfiguration());
f = secFrame;
} else {
primaryFrame = new Frame("Screen " + x + " - primary", gd[x].getDefaultConfiguration());
f = primaryFrame;
}
Button b = new Button("Print");
b.addActionListener(this);
f.add("South", b);
f.addWindowListener (new WindowAdapter() {
public void windowClosing(WindowEvent we) {
((Window) we.getSource()).dispose();
}
});
f.setSize(200, 200);
f.setVisible(true);
}
}
示例8: init
import java.awt.Button; //导入方法依赖的package包/类
@Override
public void init() {
if (OSInfo.getOSType() != OSInfo.OSType.MACOSX) {
Sysout.createDialogWithInstructions(new String[]{
"Press PASS, this test is for MacOS X only."});
return;
}
System.setProperty("apple.awt.use-file-dialog-packages", "true");
setLayout(new GridLayout(1, 1));
fd = new FileDialog(new Frame(), "Open");
fd.setDirectory(APPLICATIONS_FOLDER);
showBtn = new Button("Show File Dialog");
showBtn.addActionListener(this);
add(showBtn);
String[] instructions = {
"1) Click on 'Show File Dialog' button. A file dialog will come up.",
"2) Navigate to the Applications folder if not already there",
"3) Check that the application bundles can be selected and can not be navigated",
"4) If it's true then the test passed, otherwise it failed."};
Sysout.createDialogWithInstructions(instructions);
}
示例9: frameTest
import java.awt.Button; //导入方法依赖的package包/类
private static void frameTest() {
Panel panel =new Panel();
print = new Button("PrintDialog");
print.setActionCommand("PrintDialog");
print.addActionListener((e) -> {
PrinterJob job = PrinterJob.getPrinterJob();
PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
t.start();
start = true;
job.printDialog(aset);
});
panel.add(print);
frame = new Frame("Test Frame");
frame.setLayout (new BorderLayout ());
frame.add(panel,"South");
frame.pack();
frame.setVisible(true);
t = new Thread (() -> {
if (start) {
try {
Thread.sleep(5000);
} catch (InterruptedException ex) {}
frame.dispose();
}
});
}
示例10: frameTest
import java.awt.Button; //导入方法依赖的package包/类
private static void frameTest() {
Panel panel =new Panel();
print = new Button("PageDialog");
print.setActionCommand("PageDialog");
print.addActionListener((e) -> {
PrinterJob job = PrinterJob.getPrinterJob();
PrintRequestAttributeSet aset = new HashPrintRequestAttributeSet();
t.start();
start = true;
PageFormat pf = job.pageDialog(aset);
});
panel.add(print);
frame = new Frame("Test Frame");
frame.setLayout (new BorderLayout ());
frame.add(panel,"South");
frame.pack();
frame.setVisible(true);
t = new Thread (() -> {
if (start) {
try {
Thread.sleep(5000);
} catch (InterruptedException ex) {}
frame.dispose();
}
});
}
示例11: main
import java.awt.Button; //导入方法依赖的package包/类
public static void main(final String[] args) throws Exception {
if (sun.awt.OSInfo.getOSType() == sun.awt.OSInfo.OSType.MACOSX) {
System.err.println("This test is not for OS X. Menu.setFont() is not supported on OS X.");
return;
}
//Components initialization.
frame.setMenuBar(mb);
mb.setFont(new Font("Helvetica", Font.ITALIC, 5));
final Button button = new Button("Click Me");
button.addActionListener(new Listener());
frame.setLayout(new CardLayout());
frame.add(button, "First");
frame.setSize(400, 400);
frame.setVisible(true);
sleep();
final int fInsets = frame.getInsets().top; //Frame insets without menu.
addMenu();
final int fMenuInsets = frame.getInsets().top; //Frame insets with menu.
final int menuBarHeight = fMenuInsets - fInsets;
// There is no way to change menubar height on windows. But on windows
// we can try to split menubar in 2 rows.
for (int i = 0; i < 100 && fMenuInsets == frame.getInsets().top; ++i) {
// Fill whole menubar.
addMenu();
}
mb.remove(0);
frame.validate();
sleep();
// Test execution.
// On XToolkit, menubar font should be changed to 60.
// On WToolkit, menubar font should be changed to default and menubar
// should be splitted in 2 rows.
mb.setFont(new Font("Helvetica", Font.ITALIC, 60));
sleep();
final Robot r = new Robot();
r.setAutoDelay(200);
final Point pt = frame.getLocation();
r.mouseMove(pt.x + frame.getWidth() / 2,
pt.y + fMenuInsets + menuBarHeight / 2);
r.mousePress(InputEvent.BUTTON1_MASK);
r.mouseRelease(InputEvent.BUTTON1_MASK);
sleep();
frame.dispose();
if (clicked) {
fail("Font was not changed");
}
}
示例12: initGUI
import java.awt.Button; //导入方法依赖的package包/类
private void initGUI() {
Panel pQuery = new Panel();
Panel pCommand = new Panel();
pResult = new Panel();
pQuery.setLayout(new BorderLayout());
pCommand.setLayout(new BorderLayout());
pResult.setLayout(new BorderLayout());
Font fFont = new Font("Dialog", Font.PLAIN, 12);
txtCommand = new TextArea(5, 40);
txtCommand.addKeyListener(this);
txtResult = new TextArea(20, 40);
txtCommand.setFont(fFont);
txtResult.setFont(new Font("Courier", Font.PLAIN, 12));
butExecute = new Button("Execute");
butClear = new Button("Clear");
butExecute.addActionListener(this);
butClear.addActionListener(this);
pCommand.add("East", butExecute);
pCommand.add("West", butClear);
pCommand.add("Center", txtCommand);
gResult = new Grid();
setLayout(new BorderLayout());
pResult.add("Center", gResult);
pQuery.add("North", pCommand);
pQuery.add("Center", pResult);
fMain.add("Center", pQuery);
tTree = new Tree();
// (ulrivo): screen with less than 640 width
Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
if (d.width >= 640) {
tTree.setMinimumSize(new Dimension(200, 100));
} else {
tTree.setMinimumSize(new Dimension(80, 100));
}
gResult.setMinimumSize(new Dimension(200, 300));
fMain.add("West", tTree);
doLayout();
fMain.pack();
}
示例13: createInstructionUI
import java.awt.Button; //导入方法依赖的package包/类
private void createInstructionUI() {
mainFrame = new Frame("Updating TrayIcon Popup Menu Item Test");
layout = new GridBagLayout();
mainControlPanel = new Panel(layout);
resultButtonPanel = new Panel(layout);
GridBagConstraints gbc = new GridBagConstraints();
String instructions
= "INSTRUCTIONS:"
+ "\n 1. Click on the System Tray Icon"
+ "\n 2. Click on any of the displayed Menu items"
+ "\n 3. Repeat step 1 and count the number of items in the "
+ "Menu"
+ "\n 4. The number of items in the Menu should increase by 1"
+ "\n 5. Repeating steps 1, 2 and 3 should not break 4th step"
+ "\n 6. Click Fail if the 4th step is broken, Otherwise "
+ "click Pass ";
instructionTextArea = new TextArea();
instructionTextArea.setText(instructions);
instructionTextArea.setEnabled(false);
instructionTextArea.setBackground(Color.white);
gbc.gridx = 0;
gbc.gridy = 0;
gbc.fill = GridBagConstraints.HORIZONTAL;
mainControlPanel.add(instructionTextArea, gbc);
passButton = new Button("Pass");
passButton.setName("Pass");
passButton.addActionListener(this);
failButton = new Button("Fail");
failButton.setName("Fail");
failButton.addActionListener(this);
gbc.gridx = 0;
gbc.gridy = 0;
resultButtonPanel.add(passButton, gbc);
gbc.gridx = 1;
gbc.gridy = 0;
resultButtonPanel.add(failButton, gbc);
gbc.gridx = 0;
gbc.gridy = 1;
mainControlPanel.add(resultButtonPanel, gbc);
mainFrame.add(mainControlPanel);
mainFrame.pack();
mainFrame.setVisible(true);
}
示例14: initGUI
import java.awt.Button; //导入方法依赖的package包/类
/**
* Method declaration
*
*/
private void initGUI() {
Panel pQuery = new Panel();
Panel pCommand = new Panel();
pResult = new Panel();
pQuery.setLayout(new BorderLayout());
pCommand.setLayout(new BorderLayout());
pResult.setLayout(new BorderLayout());
Font fFont = new Font("Dialog", Font.PLAIN, 12);
txtCommand = new TextArea(5, 40);
txtCommand.addKeyListener(this);
txtResult = new TextArea(20, 40);
txtCommand.setFont(fFont);
txtResult.setFont(new Font("Courier", Font.PLAIN, 12));
butExecute = new Button("Execute");
butClear = new Button("Clear");
butExecute.addActionListener(this);
butClear.addActionListener(this);
pCommand.add("East", butExecute);
pCommand.add("West", butClear);
pCommand.add("Center", txtCommand);
gResult = new Grid();
setLayout(new BorderLayout());
pResult.add("Center", gResult);
pQuery.add("North", pCommand);
pQuery.add("Center", pResult);
fMain.add("Center", pQuery);
tTree = new Tree();
// (ulrivo): screen with less than 640 width
Dimension d = Toolkit.getDefaultToolkit().getScreenSize();
if (d.width >= 640) {
tTree.setMinimumSize(new Dimension(200, 100));
} else {
tTree.setMinimumSize(new Dimension(80, 100));
}
gResult.setMinimumSize(new Dimension(200, 300));
fMain.add("West", tTree);
doLayout();
fMain.pack();
}
示例15: initGUI
import java.awt.Button; //导入方法依赖的package包/类
/**
* Method declaration
*
*/
private void initGUI() {
Panel pQuery = new Panel();
Panel pCommand = new Panel();
// define a Panel pCard which takes four different cards/views:
// tree of tables, command SQL text area, result window and an editor/input form
pCard = new Panel();
layoutCard = new CardLayout(2, 2);
pCard.setLayout(layoutCard);
// four buttons at the top to quickly switch between the four views
butTree = new Button("Tree");
butCommand = new Button("Command");
butResult = new Button("Result");
butEditor = new Button("Editor");
butTree.addActionListener(this);
butCommand.addActionListener(this);
butResult.addActionListener(this);
butEditor.addActionListener(this);
Panel pButtons = new Panel();
pButtons.setLayout(new GridLayout(1, 4, 8, 8));
pButtons.add(butTree);
pButtons.add(butCommand);
pButtons.add(butResult);
pButtons.add(butEditor);
pResult = new Panel();
pQuery.setLayout(new BorderLayout());
pCommand.setLayout(new BorderLayout());
pResult.setLayout(new BorderLayout());
Font fFont = new Font("Dialog", Font.PLAIN, 12);
txtCommand = new TextArea(5, 40);
txtCommand.addKeyListener(this);
txtResult = new TextArea(20, 40);
txtCommand.setFont(fFont);
txtResult.setFont(new Font("Courier", Font.PLAIN, 12));
butExecute = new Button("Execute");
butExecute.addActionListener(this);
pCommand.add("South", butExecute);
pCommand.add("Center", txtCommand);
gResult = new Grid();
setLayout(new BorderLayout());
pResult.add("Center", gResult);
tTree = new Tree();
tTree.setMinimumSize(new Dimension(200, 100));
gResult.setMinimumSize(new Dimension(200, 300));
eEditor = new ZaurusEditor();
pCard.add("tree", tTree);
pCard.add("command", pCommand);
pCard.add("result", pResult);
pCard.add("editor", eEditor);
fMain.add("Center", pCard);
fMain.add("North", pButtons);
doLayout();
fMain.pack();
}