亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

java 讀取xls表格然后實現上一頁和下一頁 (寫了出來但是不能用,不知道為什么,封裝另外的類中)

java 讀取xls表格然后實現上一頁和下一頁 (寫了出來但是不能用,不知道為什么,封裝另外的類中)

九天冰塵 2016-12-25 21:36:07
package shizi;import java.awt.*;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.io.File;import javax.swing.*;import javazoom.jl.player.advanced.jlap;import jxl.Sheet;import jxl.Workbook;public class Xue_1 extends JFrame implements ActionListener{ JButton x1=new JButton("上一個"); JButton x2=new JButton("下一個"); JButton r1=new JButton("返回主菜單"); JButton r2=new JButton("切換音樂"); JButton r3=new JButton("切換背景"); JButton r4=new JButton("靜音模式"); JLabel bj2=new JLabel(new ImageIcon("image/215452.jpg")); Xinxi[] xinxis; JLabel h1=new JLabel("字"); JLabel h2=new JLabel("組詞"); JLabel h3=new JLabel("造句"); JLabel h4=new JLabel("拼音"); JLabel h5=new JLabel("喇叭"); Font font1=new Font("楷體",Font.BOLD,90); Font font2=new Font("微軟雅黑",Font.BOLD,30); int n; public Xue_1(){ Container c=this.getContentPane(); c.setLayout(null); xinxis=this.getXinxis(); h1.setBounds(270,50, 100,100); h4.setBounds(100,200, 300,70); h2.setBounds(100,260, 300,70); h3.setBounds(100,320, 300,70); h5.setBounds(410,150, 50,50); h1.setFont(font1); h2.setFont(font2); h3.setFont(font2); h4.setFont(font2); bj2.setBounds(0,0,500,600); x1.setBounds(100, 520, 100, 40); x2.setBounds(300, 520, 100, 40); r1.setBounds(0, 0, 100, 30); r2.setBounds(0, 30, 100, 30); r3.setBounds(0, 60, 100, 30); r4.setBounds(0, 90, 100, 30); x1.addActionListener(this); x2.addActionListener(this); r1.addActionListener(this); r2.addActionListener(this); r3.addActionListener(this); r4.addActionListener(this); c.add(h1); c.add(h2); c.add(h3); c.add(h4); c.add(h5); c.add(r1); c.add(r2); c.add(r3); c.add(r4); c.add(x1); c.add(x2); c.add(bj2); this.showXinxi(xinxis[0]); this.setTitle("識字板塊"); this.setSize(500, 600); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.setVisible(true); } public static void main(String[] args) { Xue_1 xue=new Xue_1(); } @Override public void actionPerformed(ActionEvent e) { this.getXinxis(); // TODO Auto-generated method stub if(e.getSource()==x1){ n--; if(n<0){ n++; JOptionPane.showMessageDialog(null, "親!已經到第一頁了!"); } }else if(e.getSource()==x2){ n++; if(n>40){ n--; JOptionPane.showMessageDialog(null, "親!已經學完了,快去做練習游戲吧!"); } }else if(e.getSource()==r1){ Jiemian_1 jm=new Jiemian_1(); }else if(e.getSource()==r2){ }else if(e.getSource()==r3){ }else if(e.getSource()==r4){ } } public Xinxi[] getXinxis(){ Xinxi[] xinxis=null; try{ File file=new File("file/1.xls"); Workbook workbook=Workbook.getWorkbook(file); Sheet sheet=workbook.getSheet(0); int rows=sheet.getRows(); int columns=sheet.getColumns(); xinxis=new Xinxi[rows]; Xinxi xx=new Xinxi(); System.out.println("n="+n); xx.setZi(sheet.getCell(0,0+n).getContents()); xx.setCi(sheet.getCell(1,0+n).getContents()); xx.setJu(sheet.getCell(2,0+n).getContents()); xx.setPinyin(sheet.getCell(3,0+n).getContents()); xx.setYuyin(sheet.getCell(4,0+n).getContents()); xinxis[n]=xx; workbook.close(); }catch(Exception ex){ ex.printStackTrace(); } return xinxis;} public void showXinxi(Xinxi xinxi){ h1.setText(xinxi.getZi()); h2.setText(xinxi.getCi()); h3.setText(xinxi.getJu()); h4.setText(xinxi.getPinyin()); h5.setText(xinxi.getYuyin()); }}
查看完整描述

1 回答

?
botao555

TA貢獻48條經驗 獲得超46個贊

你的jar包和類的代碼沒給全,自己單步調試下吧

查看完整回答
1 反對 回復 2017-05-09
  • 1 回答
  • 0 關注
  • 1823 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號