本文整理了Java中java.awt.Toolkit.getDefaultToolkit()
方法的一些代码示例,展示了Toolkit.getDefaultToolkit()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Toolkit.getDefaultToolkit()
方法的具体详情如下:
包路径:java.awt.Toolkit
类名称:Toolkit
方法名:getDefaultToolkit
[英]Gets the default toolkit.
If there is a system property named "awt.toolkit"
, that property is treated as the name of a class that is a subclass of Toolkit
.
If the system property does not exist, then the default toolkit used is the class named "sun.awt.motif.MToolkit"
, which is a motif implementation of the Abstract Window Toolkit.
Also loads additional classes into the VM, using the property 'assistive_technologies' specified in the Sun reference implementation by a line in the 'accessibility.properties' file. The form is "assistive_technologies=..." where the "..." is a comma-separated list of assistive technology classes to load. Each class is loaded in the order given and a single instance of each is created using Class.forName(class).newInstance(). This is done just after the AWT toolkit is created. All errors are handled via an AWTError exception.
[中]获取默认工具箱。
如果存在名为"awt.toolkit"
的系统属性,则该属性将被视为Toolkit
子类的类的名称。
如果系统属性不存在,那么使用的默认工具箱是名为"sun.awt.motif.MToolkit"
的类,它是抽象窗口工具箱的motif实现。
还使用Sun参考实现中指定的属性“assistive_technologies”,通过“accessibility”中的一行,将其他类加载到VM中。属性的文件。表格是“辅助技术=…”“在哪里……”是以逗号分隔的要加载的辅助技术类列表。每个类都按照给定的顺序加载,并使用类创建每个类的单个实例。forName(类)。newInstance()。这是在AWT工具包创建之后完成的。所有错误都通过AWTError异常处理。
代码示例来源:origin: log4j/log4j
/**
* @return the screen width from Toolkit.getScreenSize()
* if possible, otherwise returns 800
* @see java.awt.Toolkit
*/
protected static int getScreenWidth() {
try {
return Toolkit.getDefaultToolkit().getScreenSize().width;
} catch (Throwable t) {
return 800;
}
}
代码示例来源:origin: libgdx/libgdx
@Override
public void setContents (String content) {
try {
StringSelection stringSelection = new StringSelection(content);
java.awt.datatransfer.Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
clipboard.setContents(stringSelection, this);
} catch (Exception ignored) { // Ignore JDK crashes sorting data flavors.
}
}
代码示例来源:origin: jMonkeyEngine/jmonkeyengine
private static void createWindowForPanel(AwtPanel panel, int location){
JFrame frame = new JFrame("Render Display " + location);
frame.getContentPane().setLayout(new BorderLayout());
frame.getContentPane().add(panel, BorderLayout.CENTER);
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.addWindowListener(new WindowAdapter() {
@Override
public void windowClosed(WindowEvent e) {
if (++panelsClosed == 2){
app.stop();
}
}
});
frame.pack();
frame.setLocation(location, Toolkit.getDefaultToolkit().getScreenSize().height - 400);
frame.setVisible(true);
}
代码示例来源:origin: stackoverflow.com
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Insets scnMax = Toolkit.getDefaultToolkit().
getScreenInsets(dialog.getGraphicsConfiguration());
int taskBarSize = scnMax.bottom;
constraints.fill = GridBagConstraints.BOTH;
JLabel l = new JLabel("You have got 2 new Messages.");
panel.add(l, constraints);
constraints.gridx++;
constraints.weightx = 0f;
b.setMargin(new Insets(1, 4, 1, 4));
b.setFocusable(false);
panel.add(b, constraints);
dialog.setUndecorated(true);
dialog.setSize(300, 100);
代码示例来源:origin: kevin-wayne/algs4
/**
* Displays the picture in a window on the screen.
*/
public void show() {
// create the GUI for viewing the image if needed
if (frame == null) {
frame = new JFrame();
JMenuBar menuBar = new JMenuBar();
JMenu menu = new JMenu("File");
menuBar.add(menu);
JMenuItem menuItem1 = new JMenuItem(" Save... ");
menuItem1.addActionListener(this);
// use getMenuShortcutKeyMaskEx() in Java 10 (getMenuShortcutKeyMask() deprecated)
menuItem1.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S,
Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
menu.add(menuItem1);
frame.setJMenuBar(menuBar);
frame.setContentPane(getJLabel());
// f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
if (filename == null) frame.setTitle(width + "-by-" + height);
else frame.setTitle(filename);
frame.setResizable(false);
frame.pack();
frame.setVisible(true);
}
// draw
frame.repaint();
}
代码示例来源:origin: Nilhcem/FakeSMTP
Integer.parseInt(Configuration.INSTANCE.get("application.min.height")));
Image iconImage = Toolkit.getDefaultToolkit().getImage(
getClass().getResource(Configuration.INSTANCE.get("application.icon.path")));
mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
mainFrame.addWindowListener(new WindowAdapter() {
@Override
mainFrame.getContentPane().add(panel.get());
代码示例来源:origin: redwarp/9-Patch-Resizer
icons.add(Toolkit.getDefaultToolkit().getImage(
MainWindow.class.getResource("/img/icon_512.png")));
icons.add(Toolkit.getDefaultToolkit().getImage(
MainWindow.class.getResource("/img/icon_256.png")));
icons.add(Toolkit.getDefaultToolkit().getImage(
MainWindow.class.getResource("/img/icon_128.png")));
icons.add(Toolkit.getDefaultToolkit().getImage(
MainWindow.class.getResource("/img/icon_64.png")));
icons.add(Toolkit.getDefaultToolkit().getImage(
MainWindow.class.getResource("/img/icon_32.png")));
icons.add(Toolkit.getDefaultToolkit().getImage(
MainWindow.class.getResource("/img/icon_16.png")));
this.setIconImages(icons);
fileDialog.setTitle(Localization.get("image_types"));
this.getContentPane().add(createInputPanel(), "input");
this.getContentPane().add(createOutputPanel(), "output");
代码示例来源:origin: stackoverflow.com
tray=SystemTray.getSystemTray();
Image image=Toolkit.getDefaultToolkit().getImage("/media/faisal/DukeImg/Duke256.png");
ActionListener exitListener=new ActionListener() {
public void actionPerformed(ActionEvent e) {
defaultItem.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
setVisible(true);
setExtendedState(JFrame.NORMAL);
try {
tray.add(trayIcon);
setVisible(false);
System.out.println("added to SystemTray");
} catch (AWTException ex) {
try{
tray.add(trayIcon);
setVisible(false);
System.out.println("added to SystemTray");
}catch(AWTException ex){
setIconImage(Toolkit.getDefaultToolkit().getImage("Duke256.png"));
setVisible(true);
setSize(300, 200);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
代码示例来源:origin: geotools/geotools
private static void doShowCentred(Window parent, Window dialog) {
if (parent == null) {
doCentre(dialog, Toolkit.getDefaultToolkit().getScreenSize());
} else {
doCentre(dialog, parent.getSize());
}
dialog.setVisible(true);
}
代码示例来源:origin: stackoverflow.com
return;
final TrayIcon trayIcon = new TrayIcon(Toolkit.getDefaultToolkit().getImage(
new URL("http://home.comcast.net/~supportcd/Icons/Java_Required.jpg")), "Library Drop");
final SystemTray tray = SystemTray.getSystemTray();
try {
frame.setResizable(false);
frame.setVisible(true);
tray.add(trayIcon);
} catch (AWTException e) {
代码示例来源:origin: pmd/pmd
private void createRuleXML() {
CreateXMLRulePanel rulePanel = new CreateXMLRulePanel(xpathQueryArea, codeEditorPane);
JFrame xmlframe = new JFrame("Create XML Rule");
xmlframe.setContentPane(rulePanel);
xmlframe.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
xmlframe.setSize(new Dimension(600, 700));
xmlframe.addComponentListener(new java.awt.event.ComponentAdapter() {
@Override
public void componentResized(ComponentEvent e) {
JFrame tmp = (JFrame) e.getSource();
if (tmp.getWidth() < 600 || tmp.getHeight() < 700) {
tmp.setSize(600, 700);
}
}
});
int screenHeight = Toolkit.getDefaultToolkit().getScreenSize().height;
int screenWidth = Toolkit.getDefaultToolkit().getScreenSize().width;
xmlframe.pack();
xmlframe.setLocation((screenWidth - xmlframe.getWidth()) / 2, (screenHeight - xmlframe.getHeight()) / 2);
xmlframe.setVisible(true);
}
代码示例来源:origin: stackoverflow.com
panel.add(screenScroll, BorderLayout.CENTER);
panel.add(selectionLabel, BorderLayout.SOUTH);
final Dimension screenSize = Toolkit.getDefaultToolkit().
getScreenSize();
final BufferedImage screen = robot.createScreenCapture(
new Rectangle(screenSize));
代码示例来源:origin: log4j/log4j
/**
* @return the screen height from Toolkit.getScreenSize()
* if possible, otherwise returns 600
* @see java.awt.Toolkit
*/
protected static int getScreenHeight() {
try {
return Toolkit.getDefaultToolkit().getScreenSize().height;
} catch (Throwable t) {
return 600;
}
}
代码示例来源:origin: libgdx/libgdx
@Override
public void setContents (String content) {
try {
StringSelection stringSelection = new StringSelection(content);
java.awt.datatransfer.Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
clipboard.setContents(stringSelection, this);
} catch (Exception ignored) { // Ignore JDK crashes sorting data flavors.
}
}
代码示例来源:origin: kevin-wayne/algs4
/**
* Displays the picture in a window on the screen.
*/
public void show() {
// create the GUI for viewing the image if needed
if (frame == null) {
frame = new JFrame();
JMenuBar menuBar = new JMenuBar();
JMenu menu = new JMenu("File");
menuBar.add(menu);
JMenuItem menuItem1 = new JMenuItem(" Save... ");
menuItem1.addActionListener(this);
// use getMenuShortcutKeyMaskEx() in Java 10 (getMenuShortcutKeyMask() deprecated)
menuItem1.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S,
Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
menu.add(menuItem1);
frame.setJMenuBar(menuBar);
frame.setContentPane(getJLabel());
// f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
if (filename == null) frame.setTitle(width + "-by-" + height);
else frame.setTitle(filename);
frame.setResizable(false);
frame.pack();
frame.setVisible(true);
}
// draw
frame.repaint();
}
代码示例来源:origin: com.itextpdf/itext-rups
static void initApplication(JFrame frame, RupsController controller, final int onCloseOperation) {
// title bar
frame.setTitle("iText RUPS " + Version.getInstance().getVersion());
frame.setIconImage(Toolkit.getDefaultToolkit().getImage(Rups.class.getResource("logo.png")));
frame.setDefaultCloseOperation(onCloseOperation);
// the content
frame.setJMenuBar(controller.getMenuBar());
frame.getContentPane().add(controller.getMasterComponent(), java.awt.BorderLayout.CENTER);
frame.setVisible(true);
}
代码示例来源:origin: deathmarine/Luyten
this.setTitle(TITLE);
this.setIconImage(new ImageIcon(
Toolkit.getDefaultToolkit().getImage(this.getClass().getResource("/resources/Luyten.png"))).getImage());
this.getContentPane().add(model);
代码示例来源:origin: stackoverflow.com
import javax.swing.*;
import java.awt.*;
import java.io.*;
public class EmptyFarsiCharsOnAWT extends JFrame{
public EmptyFarsiCharsOnAWT() {
super("مثال");
setDefaultCloseOperation(3);
setVisible(rootPaneCheckingEnabled);
}
public static void main(String[] args) throws AWTException, IOException {
JFrame jFrame = new EmptyFarsiCharsOnAWT();
MenuItem show ;
// approach 1 = HardCoding :
show = new MenuItem("\u0645\u062b\u0627\u0644");
PopupMenu popUp = new PopupMenu();
popUp.add(show);
// creating Tray object
Image iconIamge = Toolkit.getDefaultToolkit().getImage("image.jpg");
TrayIcon trayIcon = new TrayIcon(iconIamge, null, popUp);
SystemTray tray = SystemTray.getSystemTray();
tray.add(trayIcon);
jFrame.setIconImage(iconIamge);
}
}
代码示例来源:origin: org.geotools/gt-swing
private static void doShowCentred(Window parent, Window dialog) {
if (parent == null) {
doCentre(dialog, Toolkit.getDefaultToolkit().getScreenSize());
} else {
doCentre(dialog, parent.getSize());
}
dialog.setVisible(true);
}
代码示例来源:origin: stackoverflow.com
import java.awt.AWTEvent;
import java.awt.MouseInfo;
import java.awt.Toolkit;
import java.awt.event.AWTEventListener;
import javax.swing.JFrame;
public class Application1 {
public static void main(String[] args) {
Toolkit.getDefaultToolkit().addAWTEventListener(
new Listener(), AWTEvent.MOUSE_EVENT_MASK | AWTEvent.FOCUS_EVENT_MASK);
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true);
}
private static class Listener implements AWTEventListener {
public void eventDispatched(AWTEvent event) {
System.out.print(MouseInfo.getPointerInfo().getLocation() + " | ");
System.out.println(event);
}
}
}
内容来源于网络,如有侵权,请联系作者删除!