当前位置: 代码迷 >> Java相关 >> java的一个基础问题
  详细解决方案

java的一个基础问题

热度:369   发布时间:2006-10-22 11:28:22.0
java的一个基础问题

类文件:


package haha;

import javax.swing.*;
import javax.swing.table.*;

/**该类保存表格的数组,定义员工总分的计算方法与排序方法*/
public class PerformanceCaculation {
//定义表格的行和列的数组
Double zero = new Double(0);
Object[][] data = {
{"李环青","男", zero, zero, zero, zero, zero, zero},
{"张东红","女", zero, zero, zero, zero, zero, zero},
{"吴贞","女", zero, zero, zero, zero, zero, zero},
{"张能求","男", zero, zero, zero, zero, zero, zero},
{"李凡到","男", zero, zero, zero, zero, zero, zero},
{"吴同凡","女", zero, zero, zero, zero, zero, zero},
{"张宽","女", zero, zero, zero, zero, zero, zero},
{"李一","男", zero, zero, zero, zero, zero, zero}
};

//定义表格的标题数组
String[] columnNames = {"姓名","性别","团队合作的分数","客户关系发展的分数",
"应付工作压力的分数","工作效率的分数","知识技能的分数","总分"};

//根据表格的行、列数组和标题数组创建表格
JTable table = new JTable(data, columnNames);
//通过表格table的模式创建表格的模式类,使用该类取得表格的数据
TableModel tableModel = table.getModel();

//定义每个员工总分的数组和分数的权重数组
double[] records = new double[8];
int[] weight = {3, 3, 1, 2, 1};

/**类的构造方法*/
public PerformanceCaculation(){
//定义表格的选择框为一个单元格
table.setColumnSelectionAllowed(true);
//设置表格的行高度
table.setRowHeight(20);
}

/**计算员工总分的方法*/
public void caculateTotal(){
for(int i = 0; i < 8; ++i) {
//清空员工总分的数值
records[i] = 0;
//取得员工的每项分数乘上每项分数的权重,计算总分数
try{
for(int j = 0; j < 5; ++j){
records[i] += Double.parseDouble(String.valueOf(tableModel.getValueAt(i,j+2)))
* weight[j];
//将各项分数放入表格数组
data[i][j+2] = tableModel.getValueAt(i,j+2);
}
//将总分放入表格数组
data[i][7] = new Double(records[i]);
//在第7列填上员工的总分数
tableModel.setValueAt(new Double(records[i]), i, 7);
}catch(Exception e){
//引入异常处理代码,如果在空格输入文字,那么总数的数值是0
records[i] = 0;
}
}
}

/**对绩效进行排序的方法*/
public void sortPerformance() {
quickSort(records, 0, records.length - 1);
//重新显示表格的内容
for(int i = 0; i < 8; ++i){
for(int j = 0; j < 8; ++j){
tableModel.setValueAt(data[i][j], i, j);
}
}
//显示前5名员工的对话框
String fiveGoodEmployee = "前5名的员工名字如下:\n";
for(int i = 7; i > 2 ; --i){
fiveGoodEmployee += data[i][0] + "\n";
}
JOptionPane.showMessageDialog(null,fiveGoodEmployee);
}

/**快速排序方法*/
public void quickSort(double[] a, int lo0, int hi0) {
int lo = lo0;
int hi = hi0;

if (lo >= hi)
return;

//确定指针方向的逻辑变量
boolean transfer=true;

while (lo != hi) {
if (a[lo] > a[hi]) {
//交换数字
double temp = a[lo];
a[lo] = a[hi];
a[hi] = temp;
//交换表格数组的记录
for(int i = 0; i < 8; ++i){
Object tempObj = new Object();
tempObj = data[lo][i];
data[lo][i] =data[hi][i];
data[hi][i] = tempObj;
}
//决定下标移动,还是上标移动
transfer = (transfer == true) ? false : true;
}

//将指针向前或者向后移动
if(transfer)
hi--;
else
lo++;
}

//将数组分开两半,确定每个数字的正确位置
lo--;
hi++;
quickSort(a, lo0, lo);
quickSort(a, hi, hi0);
}
}


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

执行文件:

package yk412;

import javax.swing.UIManager;
import java.awt.*;
import haha.*;

public class AppraisalPro {
private boolean packFrame = false;

/**构造方法*/
public AppraisalPro() {

AppraisalFrame frame = new AppraisalFrame();

//使窗口居中对齐
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension frameSize = frame.getSize();
frame.setLocation((screenSize.width - frameSize.width) / 2, (screenSize.height - frameSize.height) / 2);
//使窗口可视
frame.setVisible(true);
}

/**主方法*/
public static void main(String[] args) {
new AppraisalPro();
}
}


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

frame文件:

package yk412;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.table.*; //取得表格模式类
import javax.swing.event.*; //取得表格事件接收器
import haha.*;

public class AppraisalFrame extends JFrame {
//创建可视化窗口的各个控件
private JPanel contentPane;
private JPanel btnPanel = new JPanel();
private JButton caculateBtn = new JButton();
private JButton sortBtn = new JButton();
private JScrollPane tableScrollPane = new JScrollPane();
private JButton exitBtn = new JButton();
private JPanel labelPanel = new JPanel();
private JLabel inforLabel = new JLabel();
//创建员工绩效计算类
PerformanceCaculation performanceCaculation = new PerformanceCaculation();
//将员工绩效计算类的table控件赋给窗口的employeeTable控件
private JTable employeeTable =performanceCaculation.table;

//构造方法
public AppraisalFrame() {
try {jbInit();}catch(Exception e) {e.printStackTrace();}
}

/**窗口初始化方法*/
private void jbInit() throws Exception {
//取得窗口的面板,设置窗口的大小与标题
contentPane = (JPanel) this.getContentPane();
this.setSize(new Dimension(645, 300));
this.setTitle("员工绩效评估窗口");

//分别设置按钮的标题和加入动作接收器
caculateBtn.setText("计算");
caculateBtn.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
caculateBtn_actionPerformed(e);
}
});
sortBtn.setText("排序");
sortBtn.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
sortBtn_actionPerformed(e);
}
});
exitBtn.setText("退出");
exitBtn.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(ActionEvent e) {
exitBtn_actionPerformed(e);
}
});
//设置分数权重的信息标签
inforLabel.setText("团队合作的权重是3 客户关系发展的权重是3 应付工作压力的权重是1 " +
" 工作效率的权重是2 知识技能的权重是1");

//向标签面板加入标签
labelPanel.add(inforLabel, null);
//向表格面板加入表格
tableScrollPane.getViewport().add(employeeTable, null);
//向按钮面板加入按钮
btnPanel.add(caculateBtn, null);
btnPanel.add(sortBtn, null);
btnPanel.add(exitBtn, null);
//向底层面板加入各个控件
contentPane.add(btnPanel, BorderLayout.SOUTH);
contentPane.add(tableScrollPane, BorderLayout.CENTER);
contentPane.add(labelPanel, BorderLayout.NORTH);
}

/**退出程序时清空内存*/
protected void processWindowEvent(WindowEvent e) {
if (e.getID() == WindowEvent.WINDOW_CLOSING) {
System.exit(0);
}
}

/**退出按钮的处理代码*/
void exitBtn_actionPerformed(ActionEvent e) {
System.exit(0);
}

/**计算按钮的处理代码*/
void caculateBtn_actionPerformed(ActionEvent e) {
performanceCaculation.caculateTotal();
}

/**排序按钮的处理代码*/
void sortBtn_actionPerformed(ActionEvent e) {
//先运行计算方法,再运行排序方法
performanceCaculation.caculateTotal();
performanceCaculation.sortPerformance();
}
}

整体没错误 但是执行的时候有错误
C:\JBuilder9\jdk1.4\bin\javaw -classpath "C:\Documents and Settings\S200513020\jbproject\yk412\classes;C:\JBuilder9\jdk1.4\demo\jfc\Java2D\Java2Demo.jar;C:\JBuilder9\jdk1.4\demo\plugin\jfc\Java2D\Java2Demo.jar;C:\JBuilder9\jdk1.4\jre\lib\charsets.jar;C:\JBuilder9\jdk1.4\jre\lib\ext\dnsns.jar;C:\JBuilder9\jdk1.4\jre\lib\ext\ldapsec.jar;C:\JBuilder9\jdk1.4\jre\lib\ext\localedata.jar;C:\JBuilder9\jdk1.4\jre\lib\ext\sunjce_provider.jar;C:\JBuilder9\jdk1.4\jre\lib\im\indicim.jar;C:\JBuilder9\jdk1.4\jre\lib\jaws.jar;C:\JBuilder9\jdk1.4\jre\lib\jce.jar;C:\JBuilder9\jdk1.4\jre\lib\jsse.jar;C:\JBuilder9\jdk1.4\jre\lib\rt.jar;C:\JBuilder9\jdk1.4\jre\lib\sunrsasign.jar;C:\JBuilder9\jdk1.4\lib\dt.jar;C:\JBuilder9\jdk1.4\lib\htmlconverter.jar;C:\JBuilder9\jdk1.4\lib\tools.jar" yk412.ShoppingPro


java.lang.NoClassDefFoundError: yk412/ShoppingPro

Exception in thread "main"

就是这个错误


[此贴子已经被作者于2006-10-22 22:40:55编辑过]

搜索更多相关的解决方案: zero  java  基础  import  

----------------解决方案--------------------------------------------------------
有什么异常,在哪一行出现异常,你应该帖出来
----------------解决方案--------------------------------------------------------

C:\JBuilder9\jdk1.4\bin\javaw -classpath "C:\Documents and Settings\S200513020\jbproject\yk412\classes;C:\JBuilder9\jdk1.4\demo\jfc\Java2D\Java2Demo.jar;C:\JBuilder9\jdk1.4\demo\plugin\jfc\Java2D\Java2Demo.jar;C:\JBuilder9\jdk1.4\jre\lib\charsets.jar;C:\JBuilder9\jdk1.4\jre\lib\ext\dnsns.jar;C:\JBuilder9\jdk1.4\jre\lib\ext\ldapsec.jar;C:\JBuilder9\jdk1.4\jre\lib\ext\localedata.jar;C:\JBuilder9\jdk1.4\jre\lib\ext\sunjce_provider.jar;C:\JBuilder9\jdk1.4\jre\lib\im\indicim.jar;C:\JBuilder9\jdk1.4\jre\lib\jaws.jar;C:\JBuilder9\jdk1.4\jre\lib\jce.jar;C:\JBuilder9\jdk1.4\jre\lib\jsse.jar;C:\JBuilder9\jdk1.4\jre\lib\rt.jar;C:\JBuilder9\jdk1.4\jre\lib\sunrsasign.jar;C:\JBuilder9\jdk1.4\lib\dt.jar;C:\JBuilder9\jdk1.4\lib\htmlconverter.jar;C:\JBuilder9\jdk1.4\lib\tools.jar" yk412.ShoppingPro


java.lang.NoClassDefFoundError: yk412/ShoppingPro

Exception in thread "main"

就是这个错误

[此贴子已经被作者于2006-10-22 22:35:13编辑过]


----------------解决方案--------------------------------------------------------

yk412/ShoppingPro
没有这个类啊!


----------------解决方案--------------------------------------------------------
  相关解决方案