本文整理了Java中javax.swing.JFrame.setDefaultCloseOperation()
方法的一些代码示例,展示了JFrame.setDefaultCloseOperation()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JFrame.setDefaultCloseOperation()
方法的具体详情如下:
包路径:javax.swing.JFrame
类名称:JFrame
方法名:setDefaultCloseOperation
暂无
代码示例来源:origin: libgdx/libgdx
public void run () {
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.setSize(480, 320);
frame.setLocationRelativeTo(null);
JPanel panel = new JPanel();
frame.getContentPane().add(panel);
panel.add(new NewSlider(200, 100, 500, 0.1f, 150, 300));
frame.setVisible(true);
}
});
代码示例来源:origin: stackoverflow.com
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
Timer timer = new Timer(1000, (ActionEvent e) -> {
frame.setTitle(String.valueOf(System.currentTimeMillis()));
});
timer.setRepeats(true);
timer.start();
frame.setVisible(true);
代码示例来源:origin: stackoverflow.com
$cat HelloWorldSwing.java
package start;
import javax.swing.*;
public class HelloWorldSwing {
public static void main(String[] args) {
//Create and set up the window.
JFrame frame = new JFrame("HelloWorldSwing");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JLabel label = new JLabel("Hello World");
frame.add(label);
//Display the window.
frame.pack();
frame.setVisible(true);
}
}
class Dummy {
// just to have another thing to pack in the jar
}
代码示例来源:origin: stackoverflow.com
import java.awt.Dimension;
import javax.swing.JFrame;
public class JFrameExample {
public static void main(String[] args) {
JFrame frame = new JFrame("Hello World");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setMinimumSize(new Dimension(100, 100));
frame.setVisible(true);
}
}
代码示例来源:origin: stackoverflow.com
public static void main(String args[]) {
FrameTestBase t = new FrameTestBase();
t.add(new JComponent() {
public void paintComponent(Graphics g) {
String str = "hello world!";
t.setDefaultCloseOperation(EXIT_ON_CLOSE);
t.setSize(400, 200);
t.setVisible(true);
代码示例来源:origin: stackoverflow.com
import javax.swing.*;
public class BoxLayoutFoo extends JFrame {
public BoxLayoutFoo() {
// swap the comments below
setLayout(new BoxLayout(this, BoxLayout.LINE_AXIS)); // comment out this line
//setLayout(new BoxLayout(getContentPane(), BoxLayout.LINE_AXIS)); // uncomment this line
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
pack();
setVisible(true);
}
public static void main(String[] args) {
new BoxLayoutFoo();
}
}
代码示例来源:origin: stackoverflow.com
import javax.swing.JFrame;
import javax.swing.JLabel;
public class AnotherJFrame extends JFrame
{
public AnotherJFrame()
{
super("Another GUI");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
add(new JLabel("Empty JFrame"));
pack();
setVisible(true);
}
}
代码示例来源:origin: libgdx/libgdx
public void run () {
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.setSize(480, 320);
frame.setLocationRelativeTo(null);
JPanel panel = new JPanel();
frame.getContentPane().add(panel);
panel.add(new NewSlider(200, 100, 500, 0.1f, 150, 300));
frame.setVisible(true);
}
});
代码示例来源:origin: stackoverflow.com
private void makeGUI()
{
final JFrame f = new JFrame();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.getContentPane().setLayout(new FlowLayout());
// include: "class AnswerWorker" code here.
// include: "JButton" b code here.
f.getContentPane().add(b);
f.getContentPane().add(new JButton("Nothing"));
f.pack();
f.setVisible(true);
}
代码示例来源:origin: stackoverflow.com
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JFrame;
import javax.swing.WindowConstants;
public class test {
public static void main(String[] args) {
final JFrame frame = new JFrame("Test");
frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent ev) {
//frame.dispose();
}
});
frame.setVisible(true);
}
}
代码示例来源:origin: stackoverflow.com
this.panel = new JPanel();
this.panel.setLayout(new FlowLayout());
add(panel, BorderLayout.CENTER);
JButton button = new JButton("CLICK HERE");
add(button, BorderLayout.SOUTH);
button.addActionListener(this);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(500, 500);
setVisible(true);
this.panel.add(new JButton("Button"));
this.panel.revalidate();
validate();
代码示例来源:origin: stackoverflow.com
package com.stackoverflow.test;
import java.net.URL;
import javax.swing.*; // Wild carded for brevity.
// Actual code imports single classes
public class Main {
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable(){
public void run() {
URL url = Main.class.getResource(
"/resources/stackoverflow.png");
ImageIcon icon = new ImageIcon(url);
JFrame frame = new JFrame();
frame.add(new JLabel(icon));
frame.pack();
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
});
}
}
代码示例来源:origin: libgdx/libgdx
public void run () {
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.setSize(480, 320);
frame.setLocationRelativeTo(null);
JPanel panel = new JPanel();
frame.getContentPane().add(panel);
panel.add(new Slider(200, 100, 500, 0.1f, 150, 300));
frame.setVisible(true);
}
});
代码示例来源:origin: knowm/XChange
@Override
public void run() {
// Create and set up the window.
JFrame frame = new JFrame("XChart");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add(chartPanel);
// Display the window.
frame.pack();
frame.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);
}
}
}
代码示例来源:origin: stackoverflow.com
package temp;
import java.awt.EventQueue;
import javax.swing.JFrame;
public class Main {
public static void main(String[] args) {
EventQueue.invokeLater(new Runnable() {
@Override
public void run() {
JFrame f = new JFrame();
f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
f.add(new NewJPanel());
f.pack();
f.setVisible(true);
}
});
}
}
代码示例来源:origin: libgdx/libgdx
public void run () {
JFrame frame = new JFrame();
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.setSize(480, 320);
frame.setLocationRelativeTo(null);
JPanel panel = new JPanel();
frame.getContentPane().add(panel);
panel.add(new Slider(200, 100, 500, 0.1f, 150, 300));
frame.setVisible(true);
}
});
代码示例来源:origin: knowm/XChange
@Override
public void run() {
// Create and set up the window.
JFrame frame = new JFrame("XChart");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.add(chartPanel);
// Display the window.
frame.pack();
frame.setVisible(true);
}
});
代码示例来源:origin: stackoverflow.com
public void run() {
final JFrame f = new JFrame("Say Bye Bye!");
f.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
f.addWindowListener( new WindowAdapter() {
@Override
f.setSize(300,200);
f.setLocationByPlatform(true);
f.setVisible(true);
代码示例来源:origin: stackoverflow.com
JFrame f = new JFrame("Frame " + ii);
f.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
String s =
"os.name: " + System.getProperty("os.name") +
"\nos.version: " + System.getProperty("os.version");
f.add(new JTextArea(s,3,28)); // suggest a size
f.pack();
f.setVisible(true);
内容来源于网络,如有侵权,请联系作者删除!