Salut, je suis débutant en java et je cherche comment lire un fichier excel qui se trouve sur mon ordinateur en utilisant le tableau parcourir de windows. Voila mon code java
[code=java]
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.GridLayout;
import java.awt.Image;
import java.awt.Insets;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.RenderingHints;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.filechooser.FileFilter;
public class AdminPanel extends JFrame {
private JMenuBar mbar;
private JMenu fm;
private JMenuItem open,save,savas,exit;
//private JLabel logo;
private JLabel lbl1;
private JLabel lbl2;
private JLabel lbl3;
private JButton btn;
private JButton btn1;
private JButton btn2;
private JButton btn3;
private JButton btn4;
private JButton btn5;
private JTextField txt;
private JPanel cp;
private Onglet ongl;
String path="";
File file = null;
//Image img;
public AdminPanel(){
initComponents();
}
private void initComponents() {
//logo=new JLabel();
mbar=new JMenuBar();
setJMenuBar(mbar);
fm=new JMenu("File");
open= new JMenuItem("Open File");
save= new JMenuItem("Save");
savas= new JMenuItem("Save As");
exit= new JMenuItem("Exit");
lbl1=new JLabel();
lbl2=new JLabel();
lbl3=new JLabel();
btn=new JButton();
btn1=new JButton();
btn2=new JButton();
btn3=new JButton();
btn4=new JButton();
btn5=new JButton();
txt=new JTextField();
cp=new JPanel();
ongl=new Onglet();
setLayout(null);
//----JMenuBar---
mbar.add(fm);
//-----JMenu---
fm.add(open);
fm.addSeparator();
fm.add(save);
fm.add(savas);
fm.addSeparator();
fm.add(exit);
//------logo-----
/*
logo.setIcon(new ImageIcon(getClass().getResource("/logoUFE.jpg")));
add(logo);
logo.setBounds(1, -18, 915, 185);*/
//---------Cas Spéciaux-----
btn.setText("Cas Spéciaux");
btn.setFont(lbl1.getFont().deriveFont(lbl1.getFont().getStyle() | Font.BOLD, lbl1.getFont().getSize() + 2f));
add(btn);
btn.setBounds(900, 50, 90, 80);
//---------repêchage-----
btn1.setText("Repêchage");
btn1.setFont(lbl1.getFont().deriveFont(lbl1.getFont().getStyle() | Font.BOLD, lbl1.getFont().getSize() + 2f));
add(btn1);
btn1.setBounds(900, 150, 90, 80);
//--------------Cas de Jury----
btn2.setText("Cas de Jury");
btn2.setFont(lbl1.getFont().deriveFont(lbl1.getFont().getStyle() | Font.BOLD, lbl1.getFont().getSize() + 2f));
add(btn2);
btn2.setBounds(900, 250, 90, 80);
//--------------C----
btn3.setText("");
btn3.setFont(lbl1.getFont().deriveFont(lbl1.getFont().getStyle() | Font.BOLD, lbl1.getFont().getSize() + 2f));
add(btn3);
btn3.setBounds(900, 350, 90, 80);
//--------------C----
btn4.setText("");
btn4.setFont(lbl1.getFont().deriveFont(lbl1.getFont().getStyle() | Font.BOLD, lbl1.getFont().getSize() + 2f));
add(btn4);
btn4.setBounds(900, 450, 90, 80);
//--------------Print Preview----
btn5.setText("Print Preview");
btn5.setFont(lbl1.getFont().deriveFont(lbl1.getFont().getStyle() | Font.BOLD, lbl1.getFont().getSize() + 2f));
add(btn5);
btn5.setBounds(900, 550, 90, 80);
//------Onglet----
add(ongl);
ongl.setBounds(5, 10, 850, 600);
//-------Exit-----
fm.add(exit);
exit.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
System.exit(0);
}
});
//------openfile----
open.addActionListener(new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
JFileChooser chooser = new JFileChooser();
//chooser.addChoosableFileFilter(new FileFilter());
int returnVal = chooser.showOpenDialog(null);
if(returnVal == JFileChooser.APPROVE_OPTION)
{
file = chooser.getSelectedFile();
path = file.getPath();
// ImageIcon icon=new ImageIcon(path);
//text.setText(path);
repaint();
}
}
});
{
Dimension preferredSize = new Dimension();
for(int i = 0; i < getComponentCount(); i++) {
Rectangle bounds = getComponent(i).getBounds();
preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
}
Insets insets = getInsets();
preferredSize.width += insets.right;
preferredSize.height += insets.bottom;
setMinimumSize(preferredSize);
setPreferredSize(preferredSize);
}
}
public static void main(String[]args)
{
AdminPanel ap=new AdminPanel();
ap.setTitle("Administrateur");
ap.setVisible(true);
ap.setBounds(200, 50, 950,570);
//ap.getContentPane().setBackground(Color.WHITE);
ap.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
}
}
/code=java
Afficher la suite