云大JAVA实验12Lab#12(陆歌浩)

2019-08-31 22:14

云南大学软件学院 实验报告

课程: Java程序设计实验 学期: 2012-2013学年 第一学期 任课教师: 专业: 学号: 序号: 姓名: 成绩:

实验12 部署applet和应用程序

一、实验目的

练习Java中部署applet和应用程序的应用。

二、实验内容

Program 1 Purpose:

Familiarize yourself with some of Java's GUI capabilities and event handling and write a program containing these things.

Program:

Create a program to do display something close to the following: ----------------------------------- | Input Numbers | | ----------------------------- |

| | | | <<< This is a text field | ----------------------------- | | | | -------------------- |

| | Sort low to high | | <<< This is a button | -------------------- | | | | -------------------- |

| | Sort high to low | | <<< This is a button | -------------------- | | | | | | Output Numbers | | ----------------------------- |

| | | | <<< This is a text field | ----------------------------- | | | | | | -------------------- |

| | Exit Program | | <<< This is a button | -------------------- | | |

1

-----------------------------------

You will be provided with a method that takes in a String and returns to you an array of integers. ( I will write this and make it available to you. ) The String that you pass in is the one the user enters in the \numbers\text field.

You will need to have a method to sort the array that is returned (you can use bubblesort just like in the last couple of labs.) This will sort from low to high. If you do copy it out of the book, just give proper attribution.

When the \low to high\button is clicked, you should output the sorted integers in the \

When the \high to low\button is clicked, you should output the sorted integers in the \

The user should be able to change the numbers in the \and when the buttons are pressed, they sort the current numbers and output them sorted.

实验代码:

package edu.ynu.lab12;

import java.awt.*; import javax.swing.*; public class SortTest {

package edu.ynu.lab12;

import javax.swing.*;

2

public static void main(String[] args) {

EventQueue.invokeLater(new Runnable() {

public void run() { }

SortFrame frame = new SortFrame(); frame.setLocation(350,180); frame.setSize(350,380);

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

//

frame.setVisible(true);

});

} }

import java.awt.Font; import java.awt.event.*; import java.util.regex.Matcher; import java.util.regex.Pattern;

public class SortFrame extends JFrame { private JButton upButton; private JButton downButton; private JButton exitButton; private JLabel inputLabel; private JLabel outputLabel; private JTextField inputField; private JTextField outputField; private JPanel jPanel;

public SortFrame() { // 设置Windows风格 try { UIManager

.setLookAndFeel(\);

} catch (ClassNotFoundException cnfe) { cnfe.printStackTrace(); } catch (InstantiationException ie) { ie.printStackTrace(); } catch (IllegalAccessException iae) {

iae.printStackTrace(); } catch (UnsupportedLookAndFeelException ulafe) {

ulafe.printStackTrace();

}

setTitle(\孙金文-20101120007\); inputLabel = new JLabel(\); outputLabel = new JLabel(\); upButton = new JButton(\); downButton = new JButton(\); exitButton = new JButton(\); inputField = new JTextField(); outputField = new JTextField();

jPanel = new JPanel();

3

inputLabel.setFont(new Font(\, Font.BOLD, 12)); outputLabel.setFont(new Font(\, Font.BOLD, 12)); upButton.setFont(new Font(\, Font.BOLD, 12)); downButton.setFont(new Font(\, Font.BOLD, 12)); exitButton.setFont(new Font(\, Font.BOLD, 12)); outputField.setFont(new Font(\, Font.BOLD, 12)); inputField.setFont(new Font(\, Font.BOLD, 12)); // 升序排列按钮事件处理

upButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { String ascendNumbers = Ascendsort(); outputField.setText(ascendNumbers);

}

});

// 降序排列按钮事件处理

downButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { String descendNumbers = Descendsort(); outputField.setText(descendNumbers);

}

});

// 退出按钮事件处理

exitButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent evt) { System.exit(0);

}

});

GroupLayout jPanel1Layout = new GroupLayout(jPanel); jPanel.setLayout(jPanel1Layout); jPanel1Layout .setHorizontalGroup(jPanel1Layout .createParallelGroup(GroupLayout.Alignment.LEADING) .addGroup( GroupLayout.Alignment.TRAILING, jPanel1Layout .createSequentialGroup()

.addContainerGap(90, Short.MAX_VALUE) .addGroup( jPanel1Layout .createParallelGroup(

GroupLayout.Alignment.LEADING)

4

.addComponent(

downButton)

.addComponent(upButton))

.addGap(99, 99, 99))

.addGroup(

GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup() .addContainerGap(101, Short.MAX_VALUE) .addComponent(exitButton)

.addGap(112, 112, 112))

.addGroup(

jPanel1Layout.createSequentialGroup() .addGap(113, 113, 113) .addComponent(outputLabel)

.addContainerGap(121, Short.MAX_VALUE))

.addGroup(

jPanel1Layout.createSequentialGroup() .addGap(112, 112, 112) .addComponent(inputLabel)

.addContainerGap(128, Short.MAX_VALUE))

.addGroup(

jPanel1Layout .createSequentialGroup() .addGap(22, 22, 22) .addGroup( jPanel1Layout .createParallelGroup( GroupLayout.Alignment.TRAILING,

false) .addComponent(

outputField,

GroupLayout.Alignment.LEADING)

.addComponent(

inputField, GroupLayout.Alignment.LEADING, GroupLayout.DEFAULT_SIZE,

272,

Short.MAX_VALUE))

.addContainerGap(24, Short.MAX_VALUE)));

jPanel1Layout

5


云大JAVA实验12Lab#12(陆歌浩).doc 将本文的Word文档下载到电脑 下载失败或者文档不完整,请联系客服人员解决!

下一篇:特殊教育说课稿 - (语文)

相关阅读
本类排行
× 注册会员免费下载(下载后可以自由复制和排版)

马上注册会员

注:下载文档有可能“只有目录或者内容不全”等情况,请下载之前注意辨别,如果您已付费且无法下载或内容有问题,请联系我们协助你处理。
微信: QQ: