Изучение графических средств создания пользовательского интерфейса платформы Java

Страницы работы

Содержание работы

Министерство образования и науки РФ

Новосибирский государственный технический университет

Кафедра вычислительной техники

Лабораторная работа № 5

по дисциплине «ООП»

Тема: Графический пользовательский интерфейс

Факультет: АВТ

Группа: АВТ-909

Студенка: Дорошенко Н.А.

Преподаватель:

Малявко А.А.

Новосибирск 2012

Цели работы

Изучить и освоить графические средства создания пользовательского интерфейса платформы Java.

Порядок выполнения работы

Ориентируясь на собственный вариант задания на курсовую работу освоить библиотеку Swing и технологию создания пользовательского интерфейса в избранной IDE, разработать и реализовать элементы интерфейса своего приложения.

Результаты выполнения задания

Исходный код программы:
public class MainFrame extends JFrame {

      private JPanel contentPane;

      /**

       * Launch the application.

       */

      public static void main(String[] args) {

             EventQueue.invokeLater(new Runnable() {

                   public void run() {

                          try {

                                MainFrame frame = new MainFrame();

                                frame.setVisible(true);

                          } catch (Exception e) {

                                e.printStackTrace();

                          }

                   }

             });

      }

      /**

       * Create the frame.

       */

      private final DefaultListModel<Plane> planesModel;

      public MainFrame() {

             setResizable(false);

             setTitle("Planes");

             setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

             setBounds(100, 100, 319, 304);

             final JList list = new JList();

            list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

             planesModel = new DefaultListModel<Plane>();       

             list.setModel(planesModel);

             final JMenuBar menuBar = new JMenuBar();

             setJMenuBar(menuBar);

             final JButton createButton = new JButton("Create plane");

             createButton.addActionListener(new ActionListener() {

                   public void actionPerformed(ActionEvent e) {

                          CreatePlaneDialog createPlaneDialog = new CreatePlaneDialog((JFrame)getParent());

                          createPlaneDialog.setVisible(true);

                          if (createPlaneDialog.isPlaneCreated()) {

                                Plane plane = createPlaneDialog.getPlane();

                                if (null != plane) {

                                      planesModel.addElement(plane);

                                } else {

                                      JOptionPane.showMessageDialog(new JFrame(), "Ошибка!", "Dialog",

                                  JOptionPane.INFORMATION_MESSAGE);

                                }                        

                                list.repaint();

                          }

                   }

             });

             menuBar.add(createButton);

             final JButton destroyButton = new JButton("Destroy plane");

             destroyButton.addActionListener(new ActionListener() {

                   public void actionPerformed(ActionEvent e) {

                          final int index = list.getSelectedIndex();

                          if (-1 != index) {

                                planesModel.remove(index);

                          }

                          list.repaint();

                   }

             });

             menuBar.add(destroyButton);

             final JButton lookButton = new JButton("Plane View");

             lookButton.addActionListener(new ActionListener() {

                   public void actionPerformed(ActionEvent e) {

                          final int index = list.getSelectedIndex();

                          PlaneView planeView;

                          if (-1 != index) {

                                planeView = new PlaneView(planesModel.get(index), (JFrame)getParent());

                                planeView.setVisible(true);

                          }

                   }

             });

             menuBar.add(lookButton);

             contentPane = new JPanel();

             contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));

             setContentPane(contentPane);

             GroupLayout gl_contentPane = new GroupLayout(contentPane);

             gl_contentPane.setHorizontalGroup(

                   gl_contentPane.createParallelGroup(Alignment.LEADING)

                         .addGroup(gl_contentPane.createSequentialGroup()

                                .addContainerGap()

                                .addComponent(list, GroupLayout.DEFAULT_SIZE, 280, Short.MAX_VALUE)

                                .addContainerGap())

             );

             gl_contentPane.setVerticalGroup(

                   gl_contentPane.createParallelGroup(Alignment.LEADING)

Похожие материалы

Информация о работе