你的主函数没有错误,你应该恢复主函数原来的样子public static void main(String[] args){
成都创新互联是一家专注于成都网站建设、网站制作与策划设计,蜀山网站建设哪家好?成都创新互联做网站,专注于网站建设10多年,网设计领域的专业建站公司;建站业务涵盖:蜀山等地区。蜀山做网站价格咨询:028-86922220
User user=new User();
user.setId(1001);
user.setName("user");
user.setStuNum("1001");
new TicketBooker(user);
}你的Java程序是在109行JCB_Year.setSelectedIndex(date.getYear()+1900-Integer.parseInt(arrayYear[0]));这句出问题了,因为今年是2018年,date.getYear()+1900=2018,2018-2014=4,JCB_Year.setSelectedIndex(4);而你的private JComboBox JCB_Year=new JComboBox(arrayYear);arrayYear是只定义了三个字符串的数组
private static final String arrayYear[]={"2014","2015","2016"};所以造成JComboBox下标Index越界,本来下标只有0到2你访问到了4.改正办法把arrayYear数组加两个元素,把private static final String arrayYear[]={"2014","2015","2016"};改成private static final String arrayYear[]={"2014","2015","2016","2017","2018"};就没问题了.注意,arrayYear数组 2019年还需要加"2019",2020年还需要加"2020"
import java.awt.Canvas;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Image;
import java.util.Random;
import javax.swing.JFrame;
class RainCanvas extends Canvas implements Runnable{
private int width, height;
private Image offScreen; // 缓冲图片
private char[][] charset; // 随机字符集合
private int[] pos; // 列的起始位置
private Color[] colors = new Color[25]; // 列的渐变颜色
public RainCanvas(int width, int height) {
this.width = width;
this.height = height;
// 生成ASCII可见字符集合
//创建一个新的随机器
Random rand = new Random();
//width/10为字符雨屏幕的宽度 height/10为字符雨屏幕的长度
//随机字符数组
charset = new char[width / 10][height / 10];
for (int i = 0; i charset.length; i++) {
for (int j = 0; j charset[i].length; j++) {
//nextInt(int n) 返回一个伪随机数,它是从此随机数生成器的序列中取出的、在 0(包括)和指定值(不包括)之间均匀分布的 int值。
//48--144代表键盘上的字母 符号 数字
//为charset数组的每个元素取值
charset[i][j] = (char) (rand.nextInt(96) + 48); }
}
// 随机化列起始位置
pos = new int[charset.length];
for (int i = 0; i pos.length; i++) {
pos[i] = rand.nextInt(pos.length);
}
// 生成从黑色到绿色的渐变颜色,最后一个保持为白色
for (int i = 0; i colors.length - 1; i++) {
//颜色渐变
colors[i] = new Color(0, 255 / colors.length * (i + 1), 0); }
//设置最底下一个的字符的颜色 0 0 255 蓝色 255 0 0 红色 255 255 255 白色 0 255 0 绿色
colors[colors.length - 1] = new Color(0, 0, 255);
setBackground(Color.black);
setSize(width, height);
setVisible(true);
}
public void startRain() {
new Thread(this).start();
}
public void drawRain() {
if (offScreen == null) {
return;
}
// Random rand = new Random();
//getGraphice()创建供绘制闭屏图像使用的图形上下文
Graphics g = offScreen.getGraphics();
//通过使用当前绘图表面的背景色进行填充来清除指定的矩形。
g.clearRect(0, 0, width, height);
//将此图形上下文的字体设置为指定字体。使用此图形上下文的所有后续文本操作均使用此字体。
g.setFont(new Font("Arial", Font.PLAIN, 14));
//
for (int i = 0; i charset.length; i++) {
//int speed = rand.nextInt(3);
for (int j = 0; j colors.length; j++) {
//去掉j只显示蓝色的一个字符 去掉charset[i].length显示黑屏
int index = (pos[i] + j) % charset[i].length;
// 将此图形上下文的当前颜色设置为指定颜色。
g.setColor(colors[j]);
//使用此图形上下文的当前字体和颜色绘制由指定字符数组给定的文本
g.drawChars(charset[i], index, 1, i * 10, index * 10);
}
pos[i] = (pos[i]+2 ) % charset[i].length;
}
}
@Override
public void update(Graphics g) {
paint(g);
}
public void run() {
while (true) {
drawRain();
repaint();
try {
Thread.sleep(50); // 可改变睡眠时间以调节速度
}
catch (InterruptedException e) {
System.out.println(e);
}
}
}
@Override
public void paint(Graphics g) {
// 当组件显示时检测是否要创建缓冲图片,在组件还不可见时调用createImage将返回null
if (offScreen == null) {
offScreen = createImage(width, height);
}
g.drawImage(offScreen, 0, 0, this);
}
}
public class ZFYTest extends JFrame{
private RainCanvas canvas = new RainCanvas(1366, 768);
public ZFYTest() {
super("ZFY");
setUndecorated(true);
setExtendedState(JFrame.MAXIMIZED_BOTH);
setVisible(true);
canvas = new RainCanvas(this.getWidth(), this.getHeight()); //canvas = new RainCanvas(800,600);
getContentPane().add(canvas);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
public static void main(String[] args) {
ZFYTest test = new ZFYTest();
test.canvas.startRain();
}
}
你的代码有很多问题,最主要的一个吧就是你的inverse函数的参数没传进去,你自己定义一个空矩阵num[][],计算秩,怎么算都是零,然后就返回 null,自然就报空指针异常了。我改好了程序,供你参考:
import java.util.Scanner;
public class Project2 {
public static void main(String[] args) {
Scanner input = new Scanner(System.in);
System.out.println("请依次输入:a11、a12、a13、a21、a22、a23、a31、a32、a33\n");
int i, j;
double[][] number = new double[3][3];
double[][] number0 = new double[3][3];
for (i = 0; i 3; i++)
for (j = 0; j 3; j++)
number[i][j] = input.nextDouble();
System.out.println("Input Matrix is :");
System.out.println(number[0][0] + " " + number[0][1] + " "
+ number[0][2]);
System.out.println(number[1][0] + " " + number[1][1] + " "
+ number[1][2]);
System.out.println(number[2][0] + " " + number[2][1] + " "
+ number[2][2]);
number0 = inverse(number);
if (number0 != null) {
System.out.println("Inverse Matrix is :");
System.out.println(number0[0][0] + " " + number0[0][1] + " "
+ number0[0][2]);
System.out.println(number0[1][0] + " " + number0[1][1] + " "
+ number0[1][2]);
System.out.println(number0[2][0] + " " + number0[2][1] + " "
+ number0[2][2]);
} else
System.out.println("矩阵的秩为零");
}
public static double[][] inverse(double[][] A) {
double z;
double A1, B, C, D, E, F, G, H, I;
// double [][] num = new double [3][3];
double[][] num0 = new double[3][3];
System.out.println("Inverse Matrix A is :");
System.out.println(A[0][0] + " " + A[0][1] + " " + A[0][2]);
System.out.println(A[1][0] + " " + A[1][1] + " " + A[1][2]);
System.out.println(A[2][0] + " " + A[2][1] + " " + A[2][2]);
z = A[0][0] * A[1][1] * A[2][2] + A[2][0] * A[0][1] * A[1][2] + A[0][2]
* A[1][0] * A[2][1] - A[0][2] * A[1][1] * A[2][0] - A[0][0]
* A[1][2] * A[2][1] - A[2][2] * A[1][0] * A[0][1];
if (z == 0)
return null;
else {
A1 = A[0][0];
B = A[0][1];
C = A[0][2];
D = A[1][0];
E = A[1][1];
F = A[1][2];
G = A[2][0];
H = A[2][1];
I = A[2][2];
num0[0][0] = 1 / z * (E * I - F * H);
num0[0][1] = 1 / z * (C * H - B * I);
num0[0][2] = 1 / z * (B * F - C * E);
num0[1][0] = 1 / z * (F * G - D * I);
num0[1][1] = 1 / z * (A1 * I - C * G);
num0[1][2] = 1 / z * (C * D - A1 * F);
num0[2][0] = 1 / z * (D * H - E * G);
num0[2][1] = 1 / z * (B * H - A1 * H);
num0[2][2] = 1 / z * (A1 * E - B * D);
return num0;
}
}
}
Connection conn;
try {
Class.forName("oracle.jdbc.driver.OracleDriver");
conn = DriverManager.getConnection("jdbc:oracle:thin:@127.0.0.1:1521:taian", "hr", "hr"); //连接Oracle
conn.setAutoCommit(false);
Statement myStat = conn.createStatement();
String sqlTxt = "update BankAccount set account=account-" + this.amount.getText() + " where accId=" + this.payOut.getText();
System.out.println("第一步 执行:" + sqlTxt);
//
try {
int affectedRow = myStat.executeUpdate(sqlTxt);
System.out.println("从汇出方扣减" + this.amount.getText() + "元,修改了" + affectedRow + "行数据.");
sqlTxt = "update BankAccount set account=account+" + this.amount.getText() + " where accId=" + this.saveIn.getText();
System.out.println("第二步 执行:" + sqlTxt);
affectedRow = myStat.executeUpdate(sqlTxt);
System.out.println("从汇入方增加" + this.amount.getText() + "元,修改了" + affectedRow + "行数据.");
// 事务成功结束, 提交
conn.commit();
} catch (SQLException sqlEx) {
System.out.println
sqlEx.printStackTrace();
// 事务中断,整体回滚到事务开始前状态
conn.rollback();
}
myStat.close();
conn.close();
} catch (Exception ex) {
System.out.println("反正是出错了.");
}
}//
改好了,你把图片的地址改一下,注意路径
import java.awt.FlowLayout;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JScrollPane;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
public class e extends JFrame implements ListSelectionListener{
private JList jl;
private JLabel b1;
private String name[]={"picture 1","picture 2","picture 3"};
private Icon icon[]={new ImageIcon("picture 1.jpg"),new ImageIcon("picture 2.jpg"),new ImageIcon("picture 3.jpg")};
public e(){
super("列表框中显示图形文件");
this.getContentPane().setLayout(new FlowLayout());
jl=new JList(name);
jl.setVisibleRowCount(3);
jl.addListSelectionListener(this);
this.getContentPane().add(new JScrollPane(jl));
b1=new JLabel("picture 1");
this.getContentPane().add(b1);
this.setSize(400,400);
this.setVisible(true);
}
public static void main(String args[]){
e ex=new e();
ex.addWindowListener(new WindowAdapter(){
public void WindowClosing(WindowEvent k){
System.exit(0);
}
});
}
public void valueChanged(ListSelectionEvent k){
b1.setIcon(icon[jl.getSelectedIndex()]);
}
}