Выполнить программу JFrame - PullRequest
       15

Выполнить программу JFrame

1 голос
/ 05 сентября 2011

как выполнить эту программу?

// Resolve class BorderLayout
import java.awt.*;
// Resolve class JFrame and JButton
import javax.swing.*;
// Definition of class FrameWithBorderLayout

public class FrameWithBorderLayout extends JFrame {// Attribute

    private JButton buttonEast; // The east button
    private JButton buttonSouth; // The south button
    private JButton buttonWest; // The west button
    private JButton buttonNorth; // The north button
    private JButton buttonCenter; // The center button
    // Constructor

    public FrameWithBorderLayout() {
        // Call super class constructor with a title
        super("Frame With Multiple Buttons");
        // Create JButton objects
        buttonEast = new JButton("East");
        buttonSouth = new JButton("South");
        buttonWest = new JButton("West");
        buttonNorth = new JButton("North");
        buttonCenter = new JButton("Center");
        // Add the JButton objects
        add(buttonEast, BorderLayout.EAST);
        add(buttonSouth, BorderLayout.SOUTH);
        add(buttonWest, BorderLayout.WEST);
        add(buttonNorth, BorderLayout.NORTH);
        add(buttonCenter, BorderLayout.CENTER);
        // Set when the close button is clicked, the application exits
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        // Reorganize the embedded components
        pack();
    }
}

--------------------------------- источник тока ------------ -------------------------

// Resolve class BorderLayout
import java.awt.*;
// Resolve class JFrame and JButton
import javax.swing.*;
// Definition of class FrameWithBorderLayout
public class test extends JFrame {

// Attribute
    private JButton buttonEast; // The east button
    private JButton buttonSouth; // The south button
    private JButton buttonWest; // The west button
    private JButton buttonNorth; // The north button
    private JButton buttonCenter; // The center button
// Constructor
    public test() {
    // Call super class constructor with a title
        super("Frame With Multiple Buttons");
        // Create JButton objects
        buttonEast = new JButton("East");
        buttonSouth = new JButton("South");
        buttonWest = new JButton("West");
        buttonNorth = new JButton("North");
        buttonCenter = new JButton("Center");
        // Add the JButton objects
        add(buttonEast, BorderLayout.EAST);
        add(buttonSouth, BorderLayout.SOUTH);
        add(buttonWest, BorderLayout.WEST);
        add(buttonNorth, BorderLayout.NORTH);
        add(buttonCenter, BorderLayout.CENTER);
        // Set when the close button is clicked, the application exits
        setDefaultCloseOperation(EXIT_ON_CLOSE);
        // Reorganize the embedded components
        pack();
    }
    public static void main(String[] args) {
        java.awt.EventQueue.invokeLater(new Runnable() {
              public void run() {
                   FrameWithBorderLayout frame = new FrameWithBorderLayout();
                   frame.setVisible(true);
              }
        });
    }
}

Ответы [ 2 ]

12 голосов
/ 05 сентября 2011

Каждая Java-программа запускается с main метода:

public static void main(String[] args) {
    java.awt.EventQueue.invokeLater(new Runnable() {
          public void run() {
               FrameWithBorderLayout frame = new FrameWithBorderLayout();
               frame.setVisible(true);
          }
    });
}

Добавьте это к вашему классу кадров.

0 голосов
/ 05 сентября 2011
FrameWithBorderLayout frameTest = new FrameWithBorderLayout();
frameTest.setVisible(true);
...