Java Code Examples for javax.swing.JFrame.setDefaultCloseOperation()

The following are Jave code examples for showing how to use setDefaultCloseOperation() of the javax.swing.JFrame class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: iTrace-Archive   File: SystemMouseTracker.java   View Source Code Vote up 7 votes
@Override
protected void displayCalibrationStatus(JFrame frame) throws Exception {
      	CalibrationStatusDisplay calibDisplay = 
      			new CalibrationStatusDisplay(frame, calibrationPoints,new java.awt.geom.Point2D.Double[9]);
      	frame.setMinimumSize(new Dimension(600,300));
      	
      	frame.add(calibDisplay);
      	
      	frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
      	frame.setExtendedState(JFrame.MAXIMIZED_BOTH);
      	frame.setVisible(true);
      	frame.setTitle("Calibration: "+new Date());
      	Insets insets = frame.getInsets();
      	int width = frame.getSize().width-(insets.left+insets.right);
      	int height = frame.getSize().height-(insets.top+insets.bottom);
      	calibDisplay.windowDimension = new Dimension(width,height);
      	frame.toFront();
      	calibDisplay.repaint();
}
 
Example 2
Project: s-store   File: GraphVisualizationPanel.java   View Source Code Vote up 6 votes
/**
 * Convenience method for creating a JFrame that displays the graph
 * @param <V>
 * @param <E>
 * @param graph
 * @param observers
 * @return
 */
public static <V, E> JFrame createFrame(Graph<V, E> graph, EventObserver<V>...observers) {
    GraphVisualizationPanel<V, E> panel = factory(graph);
    for (EventObserver<V> eo : observers) panel.EVENT_SELECT_VERTEX.addObserver(eo);
    
    // Check for a graph name
    Class<?> clazz = graph.getClass();
    String title = clazz.getCanonicalName();
    try {
        Method handle = clazz.getMethod("getName");
        if (handle != null) {
            title = handle.invoke(graph).toString();
        }
    } catch (Exception ex) {
        // Ignore anything that gets thrown at us...
    }
    
    JFrame ret = new JFrame(title);
    ret.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    ret.setLayout(new BorderLayout());
    ret.setContentPane(panel);
    ret.setSize(650, 650);
    return (ret);
}
 
Example 3
Project: marathonv5   File: PopupMenuDemo.java   View Source Code Vote up 6 votes
/**
 * Create the GUI and show it. For thread safety, this method should be
 * invoked from the event-dispatching thread.
 */
private static void createAndShowGUI() {
    // Create and set up the window.
    JFrame frame = new JFrame("PopupMenuDemo");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    // Create/set menu bar and content pane.
    PopupMenuDemo demo = new PopupMenuDemo();
    frame.setJMenuBar(demo.createMenuBar());
    frame.setContentPane(demo.createContentPane());

    // Create and set up the popup menu.
    demo.createPopupMenu();

    // Display the window.
    frame.setSize(450, 260);
    frame.setVisible(true);
}
 
Example 4
Project: marathonv5   File: DropDemo.java   View Source Code Vote up 6 votes
/**
 * Create the GUI and show it. For thread safety, this method should be
 * invoked from the event-dispatching thread.
 */
public static JFrame createAndShowGUI() {
    // Create and set up the window.
    JFrame frame = new JFrame("DropDemo");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    // Create and set up the content pane.
    JComponent newContentPane = new DropDemo();
    newContentPane.setOpaque(true); // content panes must be opaque
    frame.setContentPane(newContentPane);

    // Display the window.
    frame.pack();
    frame.setVisible(true);
    return frame;
}
 
Example 5
Project: smile_1.5.0_java7   File: Histogram3Demo.java   View Source Code Vote up 5 votes
public static void main(String[] args) {
    JFrame frame = new JFrame("Histogram 3D");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setLocationRelativeTo(null);
    frame.getContentPane().add(new Histogram3Demo());
    frame.setVisible(true);
}
 
Example 6
Project: SE2017-Team1   File: TestUtil.java   View Source Code Vote up 5 votes
public static void drawAndSave(JPanel graphDrawing, String fileName, int canvasSize) {
	JFrame frame = new JFrame("Drawing");
	frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	frame.add(graphDrawing);
	frame.setSize(canvasSize, canvasSize);
	frame.setLocationRelativeTo(null);
	frame.setVisible(true);
	exportToImage("jpg", graphDrawing, fileName);
	frame.dispose();
}
 
Example 7
Project: smile_1.5.0_java7   File: BinomialDistributionDemo.java   View Source Code Vote up 5 votes
public static void main(String[] args) {
    JFrame frame = new JFrame("Binomial Distribution");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setLocationRelativeTo(null);
    frame.getContentPane().add(new BinomialDistributionDemo());
    frame.setVisible(true);
}
 
Example 8
Project: ALTTPMenuPractice   File: MenuPractice.java   View Source Code Vote up 5 votes
/**
 * Warning with instructions for failed library loading
 */
public static void showWarning() {
	// try to set LaF
	try {
		UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
	} catch (Exception e2) {
		// do nothing
	} //end System
	JFrame x = new JFrame();
	x.setLayout(new BorderLayout());
	x.setTitle("Libraries missing");
	x.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	x.add(new JLabel(
			String.join("",
					new String[] {
							"<html>",
							"<div style=\"padding: 13px; font-size: 10px;\">",
							"Your /lib directory not contain all necessary libraries to run JInput.",
							"<br /><br />",
							"To remedy this, download the latest release of MenuSimulator from",
							"<br />",
							"https://github.com/fatmanspanda/ALTTPMenuPractice/releases",
							"<br /><br />",
							"The application will halt when you close this window.",
							"</div>",
							"</html>"
			})),
			BorderLayout.NORTH);
	x.setMinimumSize(new Dimension(500,300));
	x.setLocation(200, 200);
	x.setVisible(true);
}
 
Example 9
Project: smile_1.5.0_java7   File: LaplacianEigenmapDemo.java   View Source Code Vote up 5 votes
public static void main(String argv[]) {
    LaplacianEigenmapDemo demo = new LaplacianEigenmapDemo();
    JFrame f = new JFrame("Laplacian Eigenmap");
    f.setSize(new Dimension(1000, 1000));
    f.setLocationRelativeTo(null);
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.getContentPane().add(demo);
    f.setVisible(true);
}
 
Example 10
Project: sentimental-analyzer   File: Analyzer.java   View Source Code Vote up 5 votes
/**
 * Initialize the contents of the frame.
 */
private void initialize() {
	frame = new JFrame();
	frame.setIconImage(Toolkit.getDefaultToolkit().getImage("E:\\图片\\u=1829416607,2140971604&fm=21&gp=0.jpg"));
	frame.setType(Type.UTILITY);
	frame.setTitle("网络电影评论情感倾向性分类");
	frame.setBounds(100, 100, 639, 412);
	frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	
	JMenuBar menuBar = new JMenuBar();
	frame.setJMenuBar(menuBar);
	
	JMenu mnNewMenu = new JMenu("数据集自动标注");
	menuBar.add(mnNewMenu);
	
	JMenuItem mntmNewMenuItem_2 = new JMenuItem("自动标注");
	mnNewMenu.add(mntmNewMenuItem_2);
	
	JMenu mnNewMenu_1 = new JMenu("情感分析");
	menuBar.add(mnNewMenu_1);
	
	JMenuItem mntmNewMenuItem_3 = new JMenuItem("朴素贝叶斯算法");
	mnNewMenu_1.add(mntmNewMenuItem_3);
	
	JMenuItem mntmNewMenuItem_4 = new JMenuItem("N-Gram算法");
	mnNewMenu_1.add(mntmNewMenuItem_4);
	
	JMenuItem mntmNewMenuItem_5 = new JMenuItem("支持向量机");
	mnNewMenu_1.add(mntmNewMenuItem_5);
	
	JMenu mnNewMenu_2 = new JMenu("关于");
	menuBar.add(mnNewMenu_2);
	
	JMenuItem mntmNewMenuItem = new JMenuItem("作者");
	mnNewMenu_2.add(mntmNewMenuItem);
	
	JMenuItem mntmNewMenuItem_1 = new JMenuItem("New menu item");
	mnNewMenu_2.add(mntmNewMenuItem_1);
}
 
Example 11
Project: cuttlefish   File: MultiViewDemo.java   View Source Code Vote up 5 votes
/**
 * a driver for this demo
 */
public static void main(String[] args) {
    JFrame f = new JFrame();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.getContentPane().add(new MultiViewDemo());
    f.pack();
    f.setVisible(true);
}
 
Example 12
Project: cuttlefish   File: SubLayoutDemo.java   View Source Code Vote up 5 votes
/**
 * a driver for this demo
 */
public static void main(String[] args) {
    JFrame f = new JFrame();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.getContentPane().add(new SubLayoutDemo());
    f.pack();
    f.setVisible(true);
}
 
Example 13
Project: GameArena   File: GameArena.java   View Source Code Vote up 5 votes
/**
    * Constructor. Creates an instance of the GameArena class, and displays a window on the
    * screen upon which shapes can be drawn.
    *
    * @param width The width of the window, in pixels.
    * @param height The height of the window, in pixels.
 */
public GameArena(int width, int height)
{   
       this.arenaWidth = width;
       this.arenaHeight = height;
       this.objectCount = 0;

       // Create a window
       window = new JFrame();
       window.setTitle("Let's Play!");

       // Create a JavaFX canvas as a Swing panel.
       jfxPanel = new JFXPanel();
       jfxPanel.setPreferredSize(new java.awt.Dimension(width, height));

       window.setContentPane(jfxPanel);
       window.setResizable(false);
       window.pack();
       window.setVisible(true);
       window.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

       root = new Group();
       scene = new Scene(root, arenaWidth, arenaHeight, Color.BLACK);

       Platform.runLater(new Runnable() {
           @Override
           public void run() {
               initFX();
           }
       });
}
 
Example 14
Project: SpeechToText-REST   File: ExtendedExample.java   View Source Code Vote up 5 votes
private static void createAndShowGUI() {
  JFrame frame = new JFrame("Extended Speech Services Example");
  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  frame.add(new ExtendedExample());
  frame.pack();
  frame.setVisible(true);
  frame.setLocationRelativeTo(null);
}
 
Example 15
Project: smile_1.5.0_java7   File: GeometricDistributionDemo.java   View Source Code Vote up 5 votes
public static void main(String[] args) {
    JFrame frame = new JFrame("Geometric Distribution");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setLocationRelativeTo(null);
    frame.getContentPane().add(new GeometricDistributionDemo());
    frame.setVisible(true);
}
 
Example 16
Project: smile_1.5.0_java7   File: LaplaceInterpolationDemo.java   View Source Code Vote up 5 votes
public static void main(String[] args) {
    JFrame frame = new JFrame("Laplace Interpolation");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setLocationRelativeTo(null);
    frame.getContentPane().add(new LaplaceInterpolationDemo());
    frame.setVisible(true);
}
 
Example 17
Project: Motion_Profile_Generator   File: Gui2.java   View Source Code Vote up 4 votes
private void aboutPage()
{
	JFrame about = new JFrame();
       about.setLocationByPlatform(true);
       about.setVisible(true);
	about.setTitle("About");
	about.setBounds(100, 100, 600, 400);
	about.setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
	about.getContentPane().setLayout(null);
	
	JPanel panel = new JPanel();
	panel.setBounds(0, 0, 584, 361);
	about.getContentPane().add(panel);
	panel.setLayout(null);
	
	JLabel lblMotionProfileGenerator = new JLabel("Motion Profile Generator");
	lblMotionProfileGenerator.setFont(new Font("Arial", Font.PLAIN, 34));
	lblMotionProfileGenerator.setBounds(109, 29, 365, 64);
	panel.add(lblMotionProfileGenerator);
	
	JLabel lblVersion = new JLabel("Version 2.0.0");
	lblVersion.setFont(new Font("Arial", Font.PLAIN, 14));
	lblVersion.setBounds(82, 104, 85, 14);
	panel.add(lblVersion);
	
	JLabel lblThisProductIs = new JLabel("This product is licensed under the MIT license");
	lblThisProductIs.setFont(new Font("Arial", Font.PLAIN, 14));
	lblThisProductIs.setBounds(82, 128, 296, 14);
	panel.add(lblThisProductIs);
	
	JLabel lblDevelopers = new JLabel("Developers");
	lblDevelopers.setFont(new Font("Arial", Font.PLAIN, 14));
	lblDevelopers.setBounds(82, 152, 85, 14);
	panel.add(lblDevelopers);
	
	JLabel lblLukeMammen = new JLabel("Luke Mammen");
	lblLukeMammen.setFont(new Font("Arial", Font.PLAIN, 14));
	lblLukeMammen.setBounds(109, 176, 110, 14);
	panel.add(lblLukeMammen);
	
	JLabel lblBlakeMammen = new JLabel("Blake Mammen");
	lblBlakeMammen.setFont(new Font("Arial", Font.PLAIN, 14));
	lblBlakeMammen.setBounds(109, 200, 110, 14);
	panel.add(lblBlakeMammen);
	
	JLabel lblAcknowedgements = new JLabel("Acknowledgments");
	lblAcknowedgements.setFont(new Font("Arial", Font.PLAIN, 14));
	lblAcknowedgements.setBounds(82, 224, 150, 14);
	panel.add(lblAcknowedgements);
	
	JLabel lblJaci = new JLabel("Jaci for the path generation code");
	lblJaci.setFont(new Font("Arial", Font.PLAIN, 14));
	lblJaci.setBounds(109, 248, 250, 14);
	panel.add(lblJaci);
	
	JLabel lblJH = new JLabel("KHEngineering for the graph code");
	lblJH.setFont(new Font("Arial", Font.PLAIN, 14));
	lblJH.setBounds(109, 272, 250, 14);
	panel.add(lblJH);
}
 
Example 18
Project: jreliability   File: ReliabilityViewer.java   View Source Code Vote up 4 votes
/**
 * Constructs and views {@link JFrame} with a given title and a list of {@link ReliabilityFunction}s.
 * 
 * @param title
 *            the title
 * @param reliabilityFunctions
 *            the reliabilityFunctions
 */
public static void view(String title, Map<String, ReliabilityFunction> reliabilityFunctions) {

	try {
		UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
	} catch (Exception e) {
		e.printStackTrace();
	}

	// Setup the aspects for the plot panel
	List<Aspect> aspects = new ArrayList<>();
	aspects.add(new ReliabilityFunctionAspect());
	aspects.add(new DistributionAspect());
	aspects.add(new DensityAspect());
	aspects.add(new FailureRateAspect());
	ReliabilityFunctionPlotPanel reliabilityFunctionPlotPanel = new ReliabilityFunctionPlotPanel(aspects);
	JPanel plotPanel = reliabilityFunctionPlotPanel.get(reliabilityFunctions);

	JPanel measuresPanel = new MeasuresPanel(reliabilityFunctions);

	JFrame frame = new JFrame();

	frame.setTitle(title);
	frame.setIconImage(getImageIcon().getImage());
	frame.setPreferredSize(new Dimension(1000, 500));
	frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

	Container content = frame.getContentPane();
	frame.setLayout(new GridBagLayout());
	GridBagConstraints c = new GridBagConstraints();
	c.ipady = 10;
	c.ipadx = 10;
	c.fill = GridBagConstraints.BOTH;

	c.gridx = 0;
	c.gridy = 5;
	c.weighty = 0.5;
	content.add(measuresPanel, c);
	c.gridx = 1;
	c.gridy = 5;
	c.weightx = 1.0;
	c.weighty = 0.5;
	content.add(plotPanel, c);

	c.gridx = 0;
	c.gridy = 20;
	c.gridwidth = 2;
	c.weighty = 0.0;
	c.fill = GridBagConstraints.HORIZONTAL;
	c.anchor = GridBagConstraints.PAGE_END;
	content.add(new JLabel(" \u00A9 JReliability.org 2008-2017"), c);

	frame.pack();
	frame.setVisible(true);
}
 
Example 19
Project: openjdk-jdk10   File: bug8033699.java   View Source Code Vote up 4 votes
private static void createAndShowGUI() {
    mainFrame = new JFrame("Bug 8033699 - 8 Tests for Grouped/Non Group Radio Buttons");
    btnStart = new JButton("Start");
    btnEnd = new JButton("End");
    btnMiddle = new JButton("Middle");

    JPanel box = new JPanel();
    box.setLayout(new BoxLayout(box, BoxLayout.Y_AXIS));
    box.setBorder(BorderFactory.createTitledBorder("Grouped Radio Buttons"));
    radioBtn1 = new JRadioButton("A");
    radioBtn2 = new JRadioButton("B");
    radioBtn3 = new JRadioButton("C");

    ButtonGroup btnGrp = new ButtonGroup();
    btnGrp.add(radioBtn1);
    btnGrp.add(radioBtn2);
    btnGrp.add(radioBtn3);
    radioBtn1.setSelected(true);

    box.add(radioBtn1);
    box.add(radioBtn2);
    box.add(btnMiddle);
    box.add(radioBtn3);

    radioBtnSingle = new JRadioButton("Not Grouped");
    radioBtnSingle.setSelected(true);

    mainFrame.getContentPane().add(btnStart);
    mainFrame.getContentPane().add(box);
    mainFrame.getContentPane().add(radioBtnSingle);
    mainFrame.getContentPane().add(btnEnd);

    mainFrame.getRootPane().setDefaultButton(btnStart);
    btnStart.requestFocus();

    mainFrame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    mainFrame.setLayout(new BoxLayout(mainFrame.getContentPane(), BoxLayout.Y_AXIS));

    mainFrame.setSize(300, 300);
    mainFrame.setLocation(200, 200);
    mainFrame.setVisible(true);
    mainFrame.toFront();
}
 
Example 20
Project: JFrame   File: Source.java   View Source Code Vote up 4 votes
public void gui(){

	frame = new JFrame("Begin");
	frame.setVisible(true);
	frame.setSize(700, 500);
	frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	
	panel = new JPanel();
	panel.setBackground(Color.GREEN);
	
	button = new JButton("Click");
	label = new JLabel("Label");
	
	
	panel.add(button);
	panel.add(label);
	
	frame.add(panel); //add panel to frame
	
}