本文整理匯總了Java中java.awt.Frame.setBackground方法的典型用法代碼示例。如果您正苦於以下問題:Java Frame.setBackground方法的具體用法?Java Frame.setBackground怎麽用?Java Frame.setBackground使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類java.awt.Frame
的用法示例。
在下文中一共展示了Frame.setBackground方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: main
import java.awt.Frame; //導入方法依賴的package包/類
public static void main(String[] args) {
final Frame frame = new Frame("Test");
frame.setSize(400, 400);
frame.setBackground(FRAME_COLOR);
frame.setVisible(true);
final Dialog modalDialog = new Dialog(null, true);
modalDialog.setTitle("Modal Dialog");
modalDialog.setSize(400, 200);
modalDialog.setBackground(DIALOG_COLOR);
modalDialog.setModal(true);
new Thread(new Runnable() {
@Override
public void run() {
runTest(modalDialog, frame);
}
}).start();
modalDialog.setVisible(true);
}
示例2: testChildPropertiesWithFrameAsParent
import java.awt.Frame; //導入方法依賴的package包/類
public void testChildPropertiesWithFrameAsParent() {
parentFrame = new Frame("parent Frame");
parentFrame.setSize(WIDTH, HEIGHT);
parentFrame.setLocation(100, 400);
parentFrame.setBackground(Color.BLUE);
parentLabel = new Label("ParentForegroundAndFont");
parentFont = new Font("Courier New", Font.ITALIC, 15);
parentFrame.setForeground(Color.RED);
parentFrame.setFont(parentFont);
parentFrame.add(parentLabel);
parentFrame.setVisible(true);
frameChildWindow = new Window(parentFrame);
frameChildWindow.setSize(WIDTH, HEIGHT);
frameChildWindow.setLocation(WIDTH + 200, 400);
childLabel = new Label("ChildForegroundAndFont");
frameChildWindow.add(childLabel);
frameChildWindow.setVisible(true);
if (parentFrame.getBackground() == frameChildWindow.getBackground()) {
dispose();
throw new RuntimeException("Child Window Should NOT Inherit "
+ "Parent Frame's Background Color");
}
if (parentDialog.getForeground() == windowChild.getForeground()) {
dispose();
throw new RuntimeException("Child Window Should NOT Inherit "
+ "Parent Frame's Foreground Color");
}
if (parentDialog.getFont() == windowChild.getFont()) {
dispose();
throw new RuntimeException("Child Window Should NOT Inherit "
+ "Parent Frame's Font Color");
}
}
示例3: main
import java.awt.Frame; //導入方法依賴的package包/類
public static void main(String[] args) {
Robot robot = Util.createRobot();
Frame frame = new Frame("Frame");
frame.setBackground(Color.BLUE);
frame.setBounds(200, 50, 300, 300);
frame.setVisible(true);
Dialog dialog1 = new Dialog(frame, "Dialog 1", false);
dialog1.setBackground(Color.RED);
dialog1.setBounds(100, 100, 200, 200);
dialog1.setVisible(true);
Dialog dialog2 = new Dialog(frame, "Dialog 2", false);
dialog2.setBackground(Color.GREEN);
dialog2.setBounds(400, 100, 200, 200);
dialog2.setVisible(true);
Util.waitForIdle(robot);
Util.clickOnComp(dialog2, robot);
Util.waitForIdle(robot);
Point point = dialog1.getLocationOnScreen();
int x = point.x + (int)(dialog1.getWidth() * 0.9);
int y = point.y + (int)(dialog1.getHeight() * 0.9);
try {
if (!Util.testPixelColor(x, y, dialog1.getBackground(), 10, 100, robot)) {
throw new RuntimeException("Test FAILED: Dialog is behind the frame");
}
} finally {
frame.dispose();
dialog1.dispose();
dialog2.dispose();
}
}
示例4: main
import java.awt.Frame; //導入方法依賴的package包/類
public static void main(String[] args) throws AWTException
{
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice[] gds = ge.getScreenDevices();
if (gds.length < 2) {
System.out.println("It's a multiscreen test... skipping!");
return;
}
for (int i = 0; i < gds.length; ++i) {
GraphicsDevice gd = gds[i];
GraphicsConfiguration gc = gd.getDefaultConfiguration();
Rectangle screen = gc.getBounds();
Robot robot = new Robot(gd);
// check Robot.mouseMove()
robot.mouseMove(screen.x + mouseOffset.x, screen.y + mouseOffset.y);
Point mouse = MouseInfo.getPointerInfo().getLocation();
Point point = screen.getLocation();
point.translate(mouseOffset.x, mouseOffset.y);
if (!point.equals(mouse)) {
throw new RuntimeException(getErrorText("Robot.mouseMove", i));
}
// check Robot.getPixelColor()
Frame frame = new Frame(gc);
frame.setUndecorated(true);
frame.setSize(100, 100);
frame.setLocation(screen.x + frameOffset.x, screen.y + frameOffset.y);
frame.setBackground(color);
frame.setVisible(true);
robot.waitForIdle();
Rectangle bounds = frame.getBounds();
if (!Util.testBoundsColor(bounds, color, 5, 1000, robot)) {
throw new RuntimeException(getErrorText("Robot.getPixelColor", i));
}
// check Robot.createScreenCapture()
BufferedImage image = robot.createScreenCapture(bounds);
int rgb = color.getRGB();
if (image.getRGB(0, 0) != rgb
|| image.getRGB(image.getWidth() - 1, 0) != rgb
|| image.getRGB(image.getWidth() - 1, image.getHeight() - 1) != rgb
|| image.getRGB(0, image.getHeight() - 1) != rgb) {
throw new RuntimeException(
getErrorText("Robot.createScreenCapture", i));
}
frame.dispose();
}
System.out.println("Test PASSED!");
}
示例5: main
import java.awt.Frame; //導入方法依賴的package包/類
public static void main(final String[] args) throws AWTException {
final Frame frame = new Frame();
final Component label = new PaintNativeOnUpdate();
frame.setBackground(Color.RED);
frame.add(label);
frame.setSize(300, 300);
frame.setUndecorated(true);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
sleep();
label.repaint();// first paint
sleep();
label.repaint();// incremental paint
sleep();
Robot robot = new Robot();
robot.setAutoDelay(50);
Point point = label.getLocationOnScreen();
Color color = robot.getPixelColor(point.x + label.getWidth() / 2,
point.y + label.getHeight() / 2);
if (!color.equals(Color.GREEN)) {
System.err.println("Expected color = " + Color.GREEN);
System.err.println("Actual color = " + color);
throw new RuntimeException();
}
frame.dispose();
}
示例6: main
import java.awt.Frame; //導入方法依賴的package包/類
public static void main(String[] args) {
// to regress embedding test against old fix, call with an arg. A window will pop
// up causing awt lib to be loaded so the vm won't die with the unsatisfied link error.
if (args.length > 0) {
Frame f = new Frame();
f.setSize(300, 300);
f.setBackground(Color.white);
f.show();
}
test1();
test2();
}
示例7: testChildPropertiesWithFrameAsParent
import java.awt.Frame; //導入方法依賴的package包/類
public void testChildPropertiesWithFrameAsParent() {
parentFrame = new Frame("parent Frame");
parentFrame.setSize(WIDTH, HEIGHT);
parentFrame.setLocation(100, 400);
parentFrame.setBackground(Color.BLUE);
parentLabel = new Label("ParentForegroundAndFont");
parentFont = new Font("Courier New", Font.ITALIC, 15);
parentFrame.setForeground(Color.RED);
parentFrame.setFont(parentFont);
parentFrame.add(parentLabel);
parentFrame.setVisible(true);
frameChildDialog = new Dialog(parentFrame, "Frame's child");
frameChildDialog.setSize(WIDTH, HEIGHT);
frameChildDialog.setLocation(WIDTH + 200, 400);
childLabel = new Label("ChildForegroundAndFont");
frameChildDialog.add(childLabel);
frameChildDialog.setVisible(true);
if (parentFrame.getBackground() == frameChildDialog.getBackground()) {
dispose();
throw new RuntimeException("Child Dialog Should NOT Inherit "
+ "Parent Frame's Background Color");
}
if (parentFrame.getForeground() == frameChildDialog.getForeground()) {
dispose();
throw new RuntimeException("Child Dialog Should NOT Inherit "
+ "Parent Frame's Foreground Color");
}
if (parentFrame.getFont() == frameChildDialog.getFont()) {
dispose();
throw new RuntimeException("Child Dialog Should NOT Inherit "
+ "Parent Frame's Font Style/Color");
}
}
示例8: main
import java.awt.Frame; //導入方法依賴的package包/類
public static void main(final String[] args) throws AWTException {
ExtendedRobot robot = new ExtendedRobot();
robot.setAutoDelay(50);
final Frame frame = new Frame();
final Component label = new PaintNativeOnUpdate();
frame.setBackground(Color.RED);
frame.add(label);
frame.setSize(300, 300);
frame.setUndecorated(true);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
robot.waitForIdle(1000);
label.repaint();// first paint
robot.waitForIdle(1000);
label.repaint();// incremental paint
robot.waitForIdle(1000);
Point point = label.getLocationOnScreen();
Color color = robot.getPixelColor(point.x + label.getWidth() / 2,
point.y + label.getHeight() / 2);
if (!color.equals(Color.GREEN)) {
System.err.println("Expected color = " + Color.GREEN);
System.err.println("Actual color = " + color);
throw new RuntimeException();
}
frame.dispose();
}
示例9: main
import java.awt.Frame; //導入方法依賴的package包/類
public static void main(final String[] args) {
final GraphicsDevice[] devices =
GraphicsEnvironment.getLocalGraphicsEnvironment()
.getScreenDevices();
if (devices.length < 2 || devices[0].getDisplayModes().length < 2
|| !devices[0].isFullScreenSupported()
|| !devices[1].isFullScreenSupported()) {
System.err.println("Testcase is not applicable");
return;
}
final DisplayMode defaultDM = devices[0].getDisplayMode();
final DisplayMode[] dms = devices[0].getDisplayModes();
DisplayMode nonDefaultDM = null;
for (final DisplayMode dm : dms) {
if (!dm.equals(defaultDM)) {
nonDefaultDM = dm;
break;
}
}
if (nonDefaultDM == null) {
System.err.println("Testcase is not applicable");
return;
}
final Frame frame = new Frame();
frame.setBackground(Color.GREEN);
frame.setUndecorated(true);
try {
devices[0].setFullScreenWindow(frame);
sleep();
devices[0].setDisplayMode(nonDefaultDM);
sleep();
devices[1].setFullScreenWindow(frame);
sleep();
if (!defaultDM.equals(devices[0].getDisplayMode())) {
throw new RuntimeException("DisplayMode is not restored");
}
} finally {
// cleaning up
devices[0].setFullScreenWindow(null);
devices[1].setFullScreenWindow(null);
frame.dispose();
}
}
示例10: ComponentIsNotDrawnAfterRemoveAddTest
import java.awt.Frame; //導入方法依賴的package包/類
public ComponentIsNotDrawnAfterRemoveAddTest() {
frame = new Frame("ComponentIsNotDrawnAfterRemoveAddTest");
frame.setSize(500, 500);
frame.setLocation(200, 200);
frame.setLayout(null);
frame.setBackground(Color.RED);
panel = new Panel();
panel.setLayout(null);
panel.setBounds(25, 100, 455, 295);
panel.setBackground(Color.GREEN);
for (int i = 0; i < 10; i++) {
TestCanvas canv1 = new TestCanvas();
canv1.setBounds(i * 45 + 5, 15, 30 + i, 30 + i);
panel.add(canv1);
compList.add(canv1);
TestButton btn1 = new TestButton();
btn1.setBounds(i * 45 + 5, 60, 30 + i, 30 + i);
panel.add(btn1);
compList.add(btn1);
TestCanvas canv2 = new TestCanvas();
canv2.setBounds(i * 45 + 5, 105, 30 + i, 30 + i);
panel.add(canv2);
compList.add(canv2);
TestButton btn2 = new TestButton();
btn2.setBounds(i * 45 + 5, 150, 30 + i, 30 + i);
panel.add(btn2);
compList.add(btn2);
TestCanvas canv3 = new TestCanvas();
canv3.setBounds(i * 45 + 5, 195, 30 + i, 30 + i);
panel.add(canv3);
compList.add(canv3);
TestButton btn3 = new TestButton();
btn3.setBounds(i * 45 + 5, 240, 30 + i, 30 + i);
panel.add(btn3);
compList.add(btn3);
}
frame.add(panel);
frame.setVisible(true);
}
示例11: main
import java.awt.Frame; //導入方法依賴的package包/類
public static void main(final String[] args) {
final GraphicsDevice[] devices =
GraphicsEnvironment.getLocalGraphicsEnvironment()
.getScreenDevices();
if (devices.length < 2 || devices[0].getDisplayModes().length < 2
|| !devices[0].isFullScreenSupported()
|| !devices[1].isFullScreenSupported()) {
System.err.println("Testcase is not applicable");
return;
}
final DisplayMode defaultDM = devices[0].getDisplayMode();
final DisplayMode[] dms = devices[0].getDisplayModes();
DisplayMode nonDefaultDM = null;
for (final DisplayMode dm : dms) {
if (!dm.equals(defaultDM)) {
nonDefaultDM = dm;
break;
}
}
if (nonDefaultDM == null) {
System.err.println("Testcase is not applicable");
return;
}
try {
robot = new ExtendedRobot();
}catch(Exception ex) {
ex.printStackTrace();
throw new RuntimeException("Unexpected failure");
}
final Frame frame = new Frame();
frame.setBackground(Color.GREEN);
frame.setUndecorated(true);
try {
devices[0].setFullScreenWindow(frame);
sleep();
devices[0].setDisplayMode(nonDefaultDM);
sleep();
devices[1].setFullScreenWindow(frame);
sleep();
if (!defaultDM.equals(devices[0].getDisplayMode())) {
throw new RuntimeException("DisplayMode is not restored");
}
} finally {
// cleaning up
devices[0].setFullScreenWindow(null);
devices[1].setFullScreenWindow(null);
frame.dispose();
}
}
示例12: createGUI
import java.awt.Frame; //導入方法依賴的package包/類
public void createGUI() {
frame = new Frame();
frame.setTitle("ExtendedModifiersTest");
frame.setLayout(new GridLayout(1, 6));
button = new Button();
button.addKeyListener(this);
frame.add(button);
buttonLW = new LWButton();
buttonLW.addKeyListener(this);
frame.add(buttonLW);
textField = new TextField(5);
textField.addKeyListener(this);
frame.add(textField);
textArea = new TextArea(5, 5);
textArea.addKeyListener(this);
frame.add(textArea);
list = new List();
for (int i = 1; i <= 5; ++i) {
list.add("item " + i);
}
list.addKeyListener(this);
frame.add(list);
listLW = new LWList();
for (int i = 1; i <= 5; ++i) {
listLW.add("item " + i);
}
listLW.addKeyListener(this);
frame.add(listLW);
frame.setBackground(Color.gray);
frame.setSize(500, 100);
frame.setVisible(true);
frame.toFront();
}