Results 1 to 2 of 2

Thread: eclipse

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date: May:2009
    Location: sofia
    Posts: 6

    eclipse

    . generator ( generator) :


    package telephoneorganizer;


    public class ApplicationFrame extends javax.swing.JFrame {
    public ApplicationFrame() {
    //
    super();
    // frame-a
    phoneBook = new TelephoneBook();
    nameLabel = new javax.swing.JLabel();
    nameTextField = new javax.swing.JTextField();
    phoneLabel = new javax.swing.JLabel();
    phoneTextField = new javax.swing.JTextField();
    addButton = new javax.swing.JButton();
    deleteButton = new javax.swing.JButton();
    searchButton = new javax.swing.JButton();
    clearButton = new javax.swing.JButton();

    // frame-a
    setDefaultCloseOperation(javax.swing.Win dowConstants.EXIT_ON_CLOSE);
    setTitle(" ");



    //
    nameLabel.setText(":");

    phoneLabel.setText(" :");

    // Listener-
    addButton.setText("");
    addButton.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEve nt evt) {
    addButtonActionPerformed(evt);
    }
    });

    deleteButton.setText("");
    deleteButton.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEve nt evt) {
    deleteButtonActionPerformed(evt);
    }
    });

    searchButton.setText("");
    searchButton.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEve nt evt) {
    searchButtonActionPerformed(evt);
    }
    });

    clearButton.setText("");
    clearButton.addActionListener(new java.awt.event.ActionListener() {
    public void actionPerformed(java.awt.event.ActionEve nt evt) {
    clearButtonActionPerformed(evt);
    }
    });

    // GroupLayout
    javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane() );
    getContentPane().setLayout(layout);
    layout.setHorizontalGroup(
    layout.createParallelGroup(javax.swing.G roupLayout.Alignment.LEADING)
    .addGroup(layout.createSequentialGroup()
    .addContainerGap()
    .addGroup(layout.createParallelGroup(jav ax.swing.GroupLayout.Alignment.LEADING)
    .addGroup(layout.createParallelGroup(jav ax.swing.GroupLayout.Alignment.LEADING, false)
    .addComponent(nameLabel)
    .addComponent(phoneLabel)
    .addComponent(phoneTextField)
    .addComponent(nameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, 174, javax.swing.GroupLayout.PREFERRED_SIZE))
    .addComponent(clearButton))
    .addPreferredGap(javax.swing.LayoutStyle .ComponentPlacement.RELATED)
    .addGroup(layout.createParallelGroup(jav ax.swing.GroupLayout.Alignment.LEADING, false)
    .addComponent(addButton, javax.swing.GroupLayout.DEFAULT_SIZE, 106, Short.MAX_VALUE)
    .addComponent(deleteButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
    .addComponent(searchButton, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
    .addContainerGap())
    );
    layout.setVerticalGroup(
    layout.createParallelGroup(javax.swing.G roupLayout.Alignment.LEADING)
    .addGroup(layout.createSequentialGroup()
    .addContainerGap()
    .addGroup(layout.createParallelGroup(jav ax.swing.GroupLayout.Alignment.BASELINE)
    .addComponent(nameLabel)
    .addComponent(addButton))
    .addPreferredGap(javax.swing.LayoutStyle .ComponentPlacement.RELATED)
    .addGroup(layout.createParallelGroup(jav ax.swing.GroupLayout.Alignment.TRAILING)
    .addGroup(layout.createSequentialGroup()
    .addComponent(nameTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
    .addPreferredGap(javax.swing.LayoutStyle .ComponentPlacement.RELATED)
    .addComponent(phoneLabel))
    .addComponent(deleteButton))
    .addGroup(layout.createParallelGroup(jav ax.swing.GroupLayout.Alignment.LEADING)
    .addGroup(layout.createSequentialGroup()
    .addPreferredGap(javax.swing.LayoutStyle .ComponentPlacement.RELATED)
    .addComponent(phoneTextField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
    .addPreferredGap(javax.swing.LayoutStyle .ComponentPlacement.RELATED)
    .addComponent(clearButton))
    .addGroup(layout.createSequentialGroup()
    .addGap(20, 20, 20)
    .addComponent(searchButton)))
    .addContainerGap(javax.swing.GroupLayout .DEFAULT_SIZE, Short.MAX_VALUE))
    );
    pack();
    }

    private void addButtonActionPerformed(java.awt.event. ActionEvent evt) {
    //
    String name = this.nameTextField.getText();
    //
    if(name.equals("")) {
    javax.swing.JOptionPane.showMessageDialo g(this, " !!!", " e", javax.swing.JOptionPane.YES_NO_CANCEL_OP TION);
    return;
    }
    //
    String number = this.phoneTextField.getText();
    //
    if(number.equals("")) {
    javax.swing.JOptionPane.showMessageDialo g(this, " !!!", " ", javax.swing.JOptionPane.YES_NO_CANCEL_OP TION);
    return;
    }
    // '
    boolean success = this.phoneBook.addRecord(name, number);
    if(success)
    System.out.println(" ");
    else
    System.out.println(" ");
    }

    private void deleteButtonActionPerformed(java.awt.eve nt.ActionEvent evt) {
    //
    String name = this.nameTextField.getText();
    //
    if(name.equals(""))
    javax.swing.JOptionPane.showMessageDialo g(this, " !!!", " e", javax.swing.JOptionPane.YES_NO_CANCEL_OP TION);
    //
    else {
    // '
    boolean success = this.phoneBook.deleteRecord(name);
    if(success)
    System.out.println(" ");
    else
    System.out.println(" ");
    }
    }

    private void searchButtonActionPerformed(java.awt.eve nt.ActionEvent evt) {
    //
    String name = this.nameTextField.getText();
    //
    if(name.equals(""))
    javax.swing.JOptionPane.showMessageDialo g(this, " !!!", " e", javax.swing.JOptionPane.YES_NO_CANCEL_OP TION);
    else {
    //
    int index = this.phoneBook.findRecord(name);
    //
    if(index==-1)
    javax.swing.JOptionPane.showMessageDialo g(this, " ", " ", javax.swing.JOptionPane.INFORMATION_MESS AGE);
    //
    else
    //
    this.phoneTextField.setText(this.phoneBo ok.getRecords()[index].getNumber());
    }
    }

    private void clearButtonActionPerformed(java.awt.even t.ActionEvent evt) {
    //
    this.nameTextField.setText("");
    this.phoneTextField.setText("");
    }

    public static void main(String args[]) {
    java.awt.EventQueue.invokeLater(new Runnable() {
    public void run() {
    new ApplicationFrame().setVisible(true);
    }
    });
    }

    // Private
    private TelephoneBook phoneBook;
    private javax.swing.JButton addButton;
    private javax.swing.JButton clearButton;
    private javax.swing.JButton deleteButton;
    private javax.swing.JLabel nameLabel;
    private javax.swing.JTextField nameTextField;
    private javax.swing.JLabel phoneLabel;
    private javax.swing.JTextField phoneTextField;
    private javax.swing.JButton searchButton;
    }








    package telephoneorganizer;

    public class TelephoneBook {

    private Record[] records; // ,
    private int numRecords; //
    private static final int maxRecords = 1000; //

    public TelephoneBook() {
    //
    records = new Record[maxRecords];
    // 0
    numRecords = 0;
    }

    public Record[] getRecords() {
    return records;
    }

    public boolean addRecord(String name, String number) {
    //
    Record newRecord = new Record(name,number);
    //
    if(numRecords<maxRecords) {
    //
    int i=numRecords-1;
    // -
    while(i>=0 && name.compareTo(this.getRecords()[i].getName())<0){
    // ,
    this.records[i+1]=this.getRecords()[i];
    // ,
    i--;
    }
    //
    this.records[i+1]=newRecord;
    //
    numRecords++;
    // .
    return true;
    }
    else
    // .
    return false;
    }

    public int findRecord(String name) {
    // -1
    if(this.numRecords==0)
    return -1;
    // [0, )
    int left = 0;
    int right = this.numRecords-1;
    // -
    while(left<=right) {
    //
    int mid = (left+right)/2;
    int compare = name.compareTo(this.getRecords()[mid].getName());
    //
    if(compare==0)
    return mid;
    // -
    if(compare<0)
    right = mid-1;
    //
    else
    left = mid+1;
    }
    // -1
    return -1;
    }

    public boolean deleteRecord(String name) {
    // ,
    int index = findRecord(name);
    //
    if(index==-1)
    //
    return false;
    //
    for(int j=index; j<this.numRecords-1; j++)
    this.records[j] = this.getRecords()[j+1];
    //
    this.numRecords--;
    //
    return true;
    }
    }





    package telephoneorganizer;

    public class Record {
    private String name;
    private String number;

    public Record(String name, String number) {
    this.name = name;
    this.number = number;
    }

    public String getName() {
    return name;
    }

    public String getNumber() {
    return number;
    }
    }



    http://www.snimka.bg/album.php?album_id=377911 pls help

  2. #2
    Registered User
    Join Date: Dec:2007
    Location: Sofia
    Posts: 366

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Copyright © 1999-2011 . .
iskamPC.com | mobility.BG | Bloody's Techblog | | 3D Vision Blog |