哥伦比亚的概况:我是一名学软件的学生,有那位高手知道如何编写有300行代码的JAVA程序?

来源:百度文库 编辑:杭州交通信息网 时间:2024/05/05 12:21:42

首先,你的程序必须要用300行以上的代码才能完成,这样程序才应该达到300行以上;好的程序应该尽量简洁。

其次,程序如果真的需要300行以上的代码,那么这个程序已经有点规模了,你需要利用些软件工程的知识将你的程序组织好,比如采用合适的子程序对任务进行划分,使程序易于编写。

最后,你的能力应该达到一定水平,才能处理好大程序的编写。为增强这方面的能力,《数据结构》是必须熟练掌握的,《软件工程》等也是很有帮助的,但是小花招一类的所谓技巧则是有害的。

真正好的程序应该是:1、能创造价值;2、简洁、高效;3、健壮稳定,不怕非法输入的攻击;4、易于读懂。

祝你好运!

不是吧?一名学软件的学生都要来这个问如何编写300行代码的java程序?读什么书啊?要自我检讨了!!!

提示:应用基本的语法编写一些简单的程序,比如算N个数的平均值,和等。再是算一些特定公式的例子,复杂点可以写个画图程序什么的。应该不会很难吧,未来的程序员?

程序不在于长短,编程是来解决问题的!
如果一味的要写长程序,不如多练习练习输入输出得了!

差不多300行了!
/* 本程序使用常见组件设计一个用于输入学生信息的用户界面 */

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.event.*;
import java.io.*;

public class Example0701_Components extends JFrame implements ActionListener
{
JTextField name;
JPasswordField password;
JRadioButton male;
JRadioButton female;
JCheckBox party;
JSpinner age;
JButton selectColor;
JPanel color;
JSlider addition;
JComboBox department;
JList course;
JButton confirm;
JButton save;
JTextArea result;
JProgressBar progbar;
JLabel time;

public Example0701_Components()
{
setTitle("Components usage in inputting the information of students");
setDefaultCloseOperation(EXIT_ON_CLOSE);

buildContentPane();

setExtendedState(MAXIMIZED_BOTH);
setVisible(true);
}

public void buildContentPane()
{
name = new JTextField();

password = new JPasswordField();

male = new JRadioButton("男", true);
female = new JRadioButton("女");
ButtonGroup group = new ButtonGroup();
group.add(male);
group.add(female);

party = new JCheckBox("", false);

age = new JSpinner();
age.setValue(new Integer(20));
age.addChangeListener(new ChangeListener()
{
public void stateChanged(ChangeEvent evt)
{
Integer v = (Integer)age.getValue();
int value = v.intValue();

if (value <= 15)
{
age.setValue(new Integer(15));
}

if (value >= 25)
{
age.setValue(new Integer(25));
}
}
});

color = new JPanel();
color.setBorder(BorderFactory.createLineBorder(Color.BLUE));

addition = new JSlider(JSlider.HORIZONTAL, 0, 100, 50);
addition.setMajorTickSpacing(10);
addition.setMinorTickSpacing(5);
addition.setPaintTicks(true);
addition.setPaintLabels(true);
addition.setSnapToTicks(true);

String[] departmentNames = {
"计算机科学与技术系",
"电子信息与技术系",
"计算机工程系"
};
department = new JComboBox(departmentNames);
department.setEditable(false);

String[] coursesNames = {
"数据结构",
"操作系统",
"网络原理",
"Java程序设计",
"分布式系统开发技术",
"计算机导论",
"密码学",
"计算机组成原理",
"编译原理",
"图形学"
};
course = new JList(coursesNames);
course.setVisibleRowCount(5);

confirm = new JButton("确认");
confirm.addActionListener(this);

save = new JButton("保存");
save.addActionListener(this);

result = new JTextArea();

time = new JLabel("计时开始...");

progbar = new JProgressBar(JProgressBar.HORIZONTAL,0,100);
progbar.setStringPainted(true);

Timer timer = new Timer(1000, new ActionListener()
{
public void actionPerformed(ActionEvent evt)
{
java.text.SimpleDateFormat sf = new java.text.SimpleDateFormat("yyyy 年 M 月 d 日 hh : mm : ss");
time.setText(sf.format(new java.util.Date()));

if (progbar.getValue() >= 100) progbar.setValue(0);
progbar.setValue(progbar.getValue() + 5);
}
});
timer.start();

Box boxName = Box.createHorizontalBox();
boxName.add(new JLabel("姓名"));
boxName.add(name);

Box boxPassword = Box.createHorizontalBox();
boxPassword.add(new JLabel("密码"));
boxPassword.add(password);

Box boxSexPartyAgeColor = Box.createHorizontalBox();
boxSexPartyAgeColor.add(new JLabel("性别"));
boxSexPartyAgeColor.add(male);
boxSexPartyAgeColor.add(female);
boxSexPartyAgeColor.add(Box.createHorizontalGlue());
boxSexPartyAgeColor.add(new JLabel("党否"));
boxSexPartyAgeColor.add(party);
boxSexPartyAgeColor.add(Box.createHorizontalGlue());
boxSexPartyAgeColor.add(new JLabel("年龄"));
boxSexPartyAgeColor.add(age);
boxSexPartyAgeColor.add(Box.createHorizontalGlue());
selectColor = new JButton("选择颜色");
selectColor.addActionListener(this);
boxSexPartyAgeColor.add(selectColor);
boxSexPartyAgeColor.add(Box.createHorizontalStrut(10));
boxSexPartyAgeColor.add(color);

Box boxAge = Box.createHorizontalBox();

Box boxAddition = Box.createHorizontalBox();
boxAddition.add(new JLabel("加分"));
boxAddition.add(addition);

Box box1 = Box.createVerticalBox();
box1.add(Box.createVerticalStrut(20));
box1.add(boxName);
box1.add(Box.createVerticalStrut(20));
box1.add(boxPassword);
box1.add(Box.createVerticalStrut(20));
box1.add(boxSexPartyAgeColor);
box1.add(Box.createVerticalStrut(20));
box1.add(boxAddition);
box1.add(Box.createVerticalStrut(20));

Box butt = Box.createHorizontalBox();
butt.add(confirm);
butt.add(Box.createHorizontalStrut(10));
butt.add(save);

Box box2 = Box.createVerticalBox();
box2.add(new JLabel("系别"));
box2.add(department);
box2.add(Box.createVerticalStrut(10));
box2.add(new JLabel("选课"));
box2.add(new JScrollPane(course));
box2.add(Box.createVerticalStrut(10));
box2.add(butt);

Box box = Box.createHorizontalBox();
box.setBorder(BorderFactory.createTitledBorder("请输入学生信息"));
box.add(box1);
box.add(Box.createHorizontalStrut(20));
box.add(new JSeparator(JSeparator.VERTICAL));
box.add(Box.createHorizontalStrut(20));
box.add(box2);

JSplitPane split = new JSplitPane(JSplitPane.VERTICAL_SPLIT, true, box, new JScrollPane(result));

JPanel panel = new JPanel();
panel.setLayout(new GridLayout(1,3));
panel.add(new JLabel("作者:QSP 2005 年 10 月"));
panel.add(time);
panel.add(progbar);

JLabel title = new JLabel("学生信息录入系统", new ImageIcon("mouse.gif"), JLabel.CENTER);
title.setHorizontalTextPosition(JLabel.LEFT);
title.setForeground(Color.BLUE);
title.setFont(new Font("黑体", Font.BOLD, 36));

Container con = getContentPane();
con.add(title, "North");
con.add(split, "Center");
con.add(panel, "South");
}

public void actionPerformed(ActionEvent evt)
{
if (evt.getSource() == selectColor)
{
Color c = JColorChooser.showDialog(this, "请选择你所喜欢的颜色", color.getBackground());
color.setBackground(c);
}

if (evt.getSource() == confirm)
{
String nameStr = name.getText();
if (nameStr.equals(""))
{
JOptionPane.showMessageDialog(this, "姓名不能为空!");
name.requestFocus();
return;
}

int ret = JOptionPane.showConfirmDialog(this, "确认信息是正确的吗?");
if (ret != JOptionPane.YES_OPTION) return;

StringBuffer courses = new StringBuffer();
Object[] selectedCourses = course.getSelectedValues();
for (int i = 0 ; i < selectedCourses.length ; i++)
{
courses.append((String)selectedCourses[i]);
if (i < selectedCourses.length - 1)
{
courses.append(",");
}
}

String student =
nameStr + "," +
"密码(" + new String(password.getPassword()) + ")," +
(male.isSelected() ? "男," : "女,") +
(party.isSelected() ? "党员," : "") +
"现年" + age.getValue() + "岁," +
"喜欢" + color.getBackground() + "颜色," +
"可得到加分" + addition.getValue() + "," +
"在" + department.getSelectedItem() + "学习," ;
+"选修的课程有:" + courses + "\n";

result.append(student);
}

if (evt.getSource() == save)
{
JFileChooser fc = new JFileChooser();
if (JFileChooser.APPROVE_OPTION == fc.showSaveDialog(this))
{
try
{
File f = fc.getSelectedFile();
FileWriter fw = new FileWriter(f);

fw.write(result.getText());
fw.close();
}
catch (IOException e)
{
JOptionPane.showMessageDialog(this, "文件 IO 异常!");
}
}
}
}

public static void main(String[] args)
{
new Example0701_Components();
}
}

记住括号一定要占一行.
其它的就帮不上你什么了.

用JBuilder的环境新建一个文件,他自动给你生成的代码就可以混掉很多行了