Newsgroup: it.comp.java
Titolo: Sto diventando folle, perchè non mi crea questo package

Allora ho provato a creare questo package ma non ce la faccio più non riesco
a capire cosa devo fare per risolvere il problema. Io qua vi allego i file
delle due classi che ho inserito in un unico package e il programma che
dovrebbe usarle(il programma, che tra le altre cose stavo copiando da un
libro per prova) non l'ho scritto tutto ma solo una parte. Vi allego anche
gli errori che mi vengono dati se qualcuno mi può far capire gliene sarai
grato.
//prima classe;
package file.flussi;
import java.awt.*;
import javax.swing.*;
public class BankUI extends JPanel {
    protected final static String names[]={"Account number", "First name",
"Last name", "Balance"};
    protected JLabel labels[];
    protected JTextField fields[];
    protected JButton doTask, doTask2;
    protected JPanel innerPanelCenter, innerPanelSouth;
    protected int size=4;
    public static final int ACCOUNT=0, FIRST=1, LAST=2, BALANCE=3,
TRANSACTION=4;
    public BankUI() {
        this( 4 );
    }
    public BankUI(int mySize){
    size=mySize;
    labels =new JLabel[size];
    fields= new JTextField[size];
    for (int i=0; i<labels.length; i++)
        labels[i]=new JLabel(names[i]);
    for (int i=0; i<fields.length; i++)
        fields[i]=new JTextField();
    innerPanelCenter=new JPanel();
    innerPanelCenter.setLayout(new GridLayout(size, 2));
    for (int i=0; i<size; i++){
        innerPanelCenter.add(labels[i]);
        innerPanelCenter.add(fields[i]);
    }
    doTask=new JButton();
    doTask2=new JButton();
    innerPanelSouth= new JPanel();
    innerPanelSouth.add(doTask2);
    innerPanelSouth.add(doTask);
    setLayout(new BorderLayout());
    add(innerPanelCenter, BorderLayout.CENTER);
    add(innerPanelCenter, BorderLayout.SOUTH);
    validate();
    }
    public JButton getTask(){ return doTask; }
    public JButton getDoTask2(){ return doTask2; }
    public JTextField[] getFields(){ return fields; }
    public void clearFields(){
        for (int i=0; i<size; i++)
            fields[i].setText("");
    }
    public void setFieldValues(String s[]) throws IllegalArgumentException{
        if (s.length!=size)
            throw new IllegalArgumentException("There must be " + size + "
String in the array");
        for (int i=0; i<size; i++)
            fields[i].setText(s[i]);
    }
    public String[] getFieldValues(){
        String values[]=new String[size];
        for (int i=0; i<size; i++)
            values[i]=fields[i].getText();
        return values;
    }
}
//seconda classe;
package file.flussi;
import java.io.Serializable;
public class BankAccountRecord implements Serializable {
    private int account;
    private String firstName;
    private String lastName;
    private double balance;
    /** Creates a new instance of BankAccountRecord */
    public BankAccountRecord() {
        this(0, "", "", 0.0);
    }
    public BankAccountRecord( int acct, String first, String last, double
bal){
        setAccount(acct);
        setFirstName(first);
        setLastName(last);
        setBalance(bal);
    }
    public void setAccount(int acct){
        account=acct;
    }
    public int getAccount(){
        return account;
    }
    public void setFirstName(String first){
        firstName=first;
    }
    public String getFirstName(){
        return firstName;
    }
    public void setLastName(String last){
        lastName=last;
    }
    public String getLastName(){
        return lastName;
    }
    public void setBalance(double bal){
        balance=bal;
    }
    public double getBalance(){
        return balance;
    }
}
//programma che importa le due classi;
mport file.flussi.BankUI;
import file.flussi.BankAccountRecord;
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class CreateSequentialFile extends JFrame {
    private ObjectOutputStream output;
    private BankUI userInterface;
    private JButton enter, open;
    /** Creates a new instance of CreateSequentialFile */
    public CreateSequentialFile() {
        super ("Creating a Sequential File of Objects");
        getContentPane().setLayout(new BorderLayout());
        userInterface = new BankUi();
        enter=userInterface.getDoTask();
        enter.setText("Enter");
        enter.setEnabled(false);
        enter.addActionListener(new ActionListener(){
            public void actionPerformed (ActionEvent e){
                addRecord();
            }
        }
        );
        addWindowListener( new WindowAdapter(){
            public void windowClosing(WindowEvent e)
            {
                if(output!=null){
                    addRecord();
                    closeFile();
                }else
                    System.exit(0);
            }
        }
        );
        open=userInterface.getDoTask2();
        open.setText("Save As");
        open.addActionListener(
        new ActionListener(){
            public void actionPerformed(ActionEvent e){
                openFile();
            }
        }
        );
        getContentPane().add(userInterface, BorderLayout.CENTER);
        setSize(300, 200);
        show();
    }
    private void openFile(){
        JFileChooser fileChooser = new JFileChooser();
        fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
        int result = fileChooser.showSaveDialog(this);
        if (result==JFileChooser.CANCEL_OPTION)
            return;
        File fileName = fileChooser.getSelectedFile();
        if(fileName==null || fileName.getName().equals(""))
            JOptionPane.showMessageDialog(this, "Invalid File Name",
"Invalid File Name", JOptionPane.ERROR_MESSAGE);
        else{
            try{
                output= new ObjectOutputStream( new
FileOutputStream(fileName));
                open.setEnabled(false);
                enter.setEnabled(true);
            }catch (IOException e){
                JOptionPane.showMessageDialog(this, "Error Opening File",
"Error", JOptionPane.ERROR_MESSAGE);
            }
        }
    }
    private void closeFile(){
        try{
            output.close();
            System.exit(0);
        }catch (IOException ex){
            JOptionPane.showMessageDialog(this, "Error closing file",
"Error", JOptionPane.ERROR_MESSAGE);
            System.exit(1);
        }
    }
    public void addRecord(){
        int accountNumber=0;
        BankAccountRecord record;
        String fieldValues[]=userInterface.getFieldsValues();
        if(!fieldValues[0].equals("")){
        }
    }
    public static void main(String[] args) {
    }
}
//errori che mi vengono dati quando cerco di compilare il programma;
CreateSequentialFile.java [1:1] package file.flussi does not exist
import file.flussi.BankUI;
                   ^
CreateSequentialFile.java [2:1] package file.flussi does not exist
import file.flussi.BankAccountRecord;
                   ^
CreateSequentialFile.java [11:1] cannot access BankUI
bad class file: C:\Java\flussi\BankUI.java
file does not contain class BankUI
Please remove or make sure it appears in the correct subdirectory of the
classpath.
    private BankUI userInterface;
            ^
3 errors
Errors compiling CreateSequentialFile.

 
A occhio direi che non hai rispettato sul filesystem la struttura dei 
packages; la struttura dovrebbe essere cosi:
  myProject            --> CreateSequentialFile
     |
     |-- file
           |
           |-- flussi  --> BankUI
                       --> BankAccountRecord
Marco
-- 
reply: remove .duh.spam
http://web.ticino.com/cthulhu/