本文整理匯總了Java中java.awt.Button類的典型用法代碼示例。如果您正苦於以下問題:Java Button類的具體用法?Java Button怎麽用?Java Button使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Button類屬於java.awt包,在下文中一共展示了Button類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: InfrastructureBrowser
import java.awt.Button; //導入依賴的package包/類
public InfrastructureBrowser(final MainFrame frame, final String title) {
super(frame);
this.setName(title);
setLayout(new BorderLayout());
graphPanel = new InfrastructureGraphPanel(frame);
add(graphPanel, BorderLayout.CENTER);
Button refreshButton = new Button("Refresh");
refreshButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
loadInfrastructure();
}
});
add(refreshButton, BorderLayout.SOUTH);
service = new WebServiceHelper().getMonitoringService();
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
loadInfrastructure();
}
});
}
示例2: 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));
}
}
示例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);
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.");
}
}
示例4: main
import java.awt.Button; //導入依賴的package包/類
public static void main(String args[]) throws Exception {
Frame frame = new Frame("Frame Minimize Test");
Button b = new Button("Focus ownder");
frame.add("South", b);
frame.pack();
frame.setVisible(true);
Util.waitForIdle(null);
if (!b.hasFocus()) {
throw new RuntimeException("button is not a focus owner after showing :(");
}
frame.setExtendedState(Frame.ICONIFIED);
Util.waitForIdle(null);
frame.setExtendedState(Frame.NORMAL);
Util.waitForIdle(null);
if (!b.hasFocus()) {
throw new RuntimeException("button is not a focus owner after restoring :(");
}
}
示例5: 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);
}
示例6: init
import java.awt.Button; //導入依賴的package包/類
private void init()
{
f = new Frame("Demo");
bt1 = new Button("SIN");
bt2 = new Button("COS");
bt3 = new Button("EXIT");
mc = new MyCanvas();
p = new Panel();
f.setBounds(100, 100, 500, 500);
f.setLayout(new BorderLayout());
p.add(bt1);
p.add(bt2);
p.add(bt3);
f.add(p, BorderLayout.NORTH);
f.add(mc, BorderLayout.CENTER);
addEvent();
f.setVisible(true);
}
示例7: 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();
}
示例8: actionPerformed
import java.awt.Button; //導入依賴的package包/類
@Override
public void actionPerformed(ActionEvent ae) {
if (ae.getSource() instanceof Button) {
Button btn = (Button) ae.getSource();
switch (btn.getName()) {
case "Pass":
testPassed = true;
isInterrupted = true;
mainThread.interrupt();
break;
case "Fail":
testPassed = false;
isInterrupted = true;
mainThread.interrupt();
break;
}
}
}
示例9: 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();
setVisible(true);
}
示例10: 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);
}
}
示例11: 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.");
}
}
示例12: constructTestUI
import java.awt.Button; //導入依賴的package包/類
private static void constructTestUI() {
// here, create the items that will be tested for correct behavior
HeavyComponent = new EventBug();
Button b = (Button) HeavyComponent.add("Center", new Button("Heavy"));
LightComponent = new EventBug();
BorderedLabel b1 = (BorderedLabel) LightComponent.add("Center",
new BorderedLabel("Lite"));
HeavyComponent.addListeners(b);
LightComponent.addListeners(b1);
LightComponent.setLocation(200, 0);
HeavyComponent.setVisible(true);
LightComponent.setVisible(true);
}
示例13: performTest
import java.awt.Button; //導入依賴的package包/類
public void performTest() {
int count = 0;
Component comp = coftp.getFirstComponent(frame);
String traversal = "";
do {
comp = coftp.getComponentAfter(frame, comp);
if (comp instanceof Button) {
traversal += ((Button)comp).getLabel();
} else if (comp instanceof Frame) {
traversal += ((Frame)comp).getTitle();
}
count++;
} while(count < 3);
if (!expectedTraversal.equals(traversal)) {
dispose();
throw new RuntimeException("Incorrect Traversal. Expected : "
+ expectedTraversal + "Actual : " + traversal);
}
}
示例14: actionPerformed
import java.awt.Button; //導入依賴的package包/類
@Override
public void actionPerformed(ActionEvent ae) {
if (ae.getSource() instanceof Button) {
Button btn = (Button) ae.getSource();
switch (btn.getName()) {
case "Pass":
testPassed = true;
isInterrupted = true;
mainThread.interrupt();
break;
case "Fail":
testFailed("Dragging link from web browser Failed");
break;
}
}
}
示例15: 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);
}