PDA

View Full Version : سوال: کمک برای اجرای سورس ها



mahdy_system
یک شنبه 14 خرداد 1391, 16:56 عصر
استاد بنده یه پروژه دفترچه تلفن با جاوا خواسته

من زیاد گشتم(توی سایت های ایرانی که هیچی،خارجی هم زیاد بود ولی همه شمکل داره)

من با برنامه
NetBeans IDE 6.9.1
کار میکنم و این سرورس های که در اختیار شما دوستان می زارم توی این برنامه خطا می گرفت

لطفا یکی ببینم این سورس های که میزارم خطاشون توی چی هستش و میتونه اجراشون کنه


http://srikanthtechnologies.com/javase/PROGRAMS/PB/pb.html

این انگاری از همه بهتره کل سورس رو میتوید از آخره همون صفحه بگیرید(فقط یه خطا داره)

http://www.planet-source-code.com/Upload_PSC/ftp/Telephone_2149514122009.zip

این هم خیلی خطا داره

http://archive.devx.com/dbzone/articles/sf0701/Phonebook_java.html

این هم خیلی خطا داشت

اگر هم دوستان سورس بهتری دارن ممنون میشم معرفی کنن.

mahdy_system
یک شنبه 14 خرداد 1391, 20:19 عصر
ببخشید این کد هم انگاری هم ساده و هم خیلی خوب هستش


// The "A7DawsonMerkleyPhonebook" class.
import java.awt.*;
import hsa.Console;
import hsa.PhoneBook;

public class A7DawsonMerkleyPhoneBook
{
static Console c;
static PhoneBook b;

public static void main (String[] args)
{

c = new Console ("Dawson's Phonebook Application");
b = new PhoneBook ();
// Commands for phonebook actions

PhoneMenu ();
}


public static void PhoneMenu () // Declare Method PhoneMenu
{
c.clear (); // Clears the screen so that the Phonebook Menu can be displayed.
c.println ("Welcome to Dawson's PhoneBook.\n");
c.println ("Welcome to the main menu.");
c.println ("Please enter a number between 1 - 5. Based on whichever action you want to do");
c.println ("Please enter the number assigned to it.");
c.println ("Dawson's Phonebook personal menu:\n");
c.println ("1. Add a Contact: Adds a name of a contact and their phone number to your phonebook.");
c.println ("2. Search for a Contact: Searches for the name of a contact.");
c.println ("3. Delete a Contact: Removes an entry from the phonebook.");
c.println ("4. Edit Contact information: Changes an entry from the phonebook.");
c.println ("5. Exit Phonebook application.");
// Displays the main menu and selection of different actions the phonebook can preform.
int user; // Declares int user
int decision = c.readInt ();
// This switch registers the user's number inputed based on which action they wanted to preform.
// This switch then takes this input and register's it with a certain case depending on what number the user enters
// so that the program can be run correctly.
switch (decision)
{
case 1:
Add (); // Assigns method Add to Case 1.
break;
case 2:
Search (); // Assigns method Search to Case 2.
break;
case 3:
Delete (); // Assigns method Delete to Case 3.
break;
case 4:
Edit (); // Assigns method Edit to Case 4.
break;
case 5:
Exit (); // Assigns method Exit to Case 5.
break;
}

PhoneMenu ();
// Once the user's input is stored make the main menu appear.
}


public static void Add () //Creates a new Method to store data and commands entered by the user that are used in the add action.
{
c.clear (); // Clears screen
c.println ("1. Please enter the name of the Contact."); //Ask user for contact name.
String Cname = c.readLine (); //Store the name of the Contact in the variable name as the contact name.
c.println ("2. Please enter the number for the Contact.");
String Cnumber = c.readLine (); // Read the phone number, store in Cnumber string.
b.add (Cname, Cnumber); // Stores names in phonebook class
c.println ("/tThankyou for entering the Contact's Name.");
c.println ("/tPlease enter any key to return to the main menu.");
c.readLine (); // Registers the user's keystroke in order to return to the main menu
}


public static void Search () //Creates a new used to search for a registered Contact and their number.
{
c.clear (); // Clears Screen.
c.println ("Please Enter the name of the Contact you are searching for.");
String Cname = c.readLine (); //Stores the name of the contact to bring back the contacts name and phonebook.
String Cnumber = b.Search (Cname);
// If user enters a wrong name display message "Error".
if (Cnumber.equals (""))
{
c.println ("Searching Error.");
}
else //If they enter the right answer then display the Contact name and Number
{
c.println ("Name: " + Cname);
c.println ("Phone Number:" + Cnumber);
}
c.println ("/tPlease enter any key to return to the main menu.");
c.readLine (); // Registers the user's keystroke in order to return to the main menu.

}


public static void Delete () // Create a Delete Method
{
c.clear (); // Clears the Screen.
c.println ("1. Please enter the name of a contact you want to delete.");
String Cname = c.readLine (); //Store the name of the Contact entered by user
boolean exists = !b.lookUp (Cname).equals (""); //Checks to see if Contact is registered in phonebook.
if (exists) //If contact exists remove them from the phonebook.
{
b.remove (Cname); // Call the remove method from phonebook class.
c.println ("You have deleted the selected Contact.");
}
else //Else, display message saying contact does not exist.
{
c.println ("Contact is not registered with phonebook.");
}
c.println ("Please enter any key to return to the main menu.");
c.readLine (); //Please enter any key to return to the main menu
}


public static void Edit ()
{
c.clear (); //Clear the screen.
c.println ("__________________________________________________ ________\n");
c.println ("1. Please enter the name of the Contact you want to \nmodify.");
String Cname = c.readLine (); //Stores name that user enters.
boolean exists = !b.lookUp (Cname).equals ("");
//Create a Boolean expression in order to see if they
if (exists)
{
b.remove (Cname); // Call the remove method from phonebook class.
}
else
{
c.println ("Sorry, the contact you entered does not exist");
c.readLine ();
return;
}
}


{
c.println ("2. Please enter the new phone number for " + Cname + ".");
String Cnumber = c.readLine (); // Read the new phone number, store in string.
// Add the entry to the phonebook with the same name as before, but with
// a new number. This simulates modifying the entry.
b.add (Cname, Cnumber);
c.println ("Please enter any key to return to the main menu.");
c.readLine (); // The user presses any key to return to the menu.
}


public static void Exit ()
{
System.exit (1);
}
}


فقط به اون اولش یعنی به:


import hsa.Console;
import hsa.PhoneBook;

گیر میده!

برای از بین بردن این پیام ها توی یه سایت انگلیسی یه چیز های نوشته بود:
http://compsci.ca/v3/viewtopic.php?t=2722
البته کد رو از این جا برداشتم
http://www.javaprogrammingforums.com/whats-wrong-my-code/432-java-phonebook-assignment-small-bugs.html

اگر کسی میدونه چطوری میشه این خطا رو برطرف کرد لطفا 10 دقیقه وقتش رو به من بده

ممنون

mortezaadi
دوشنبه 15 خرداد 1391, 01:10 صبح
http://srikanthtechnologies.com/javase/PROGRAMS/PB/pb.html

این انگاری از همه بهتره کل سورس رو میتوید از آخره همون صفحه بگیرید(فقط یه خطا داره)




من این پروژه اولی رو تو eclipse اوردم خیلی راحت اجرا شد. یه چند تا باگ کوچولو هم داشت رفع شد. میتونی دانلود کنیش!
برای اوردن پروزه eclipse توی netbeans میتونی از ویزارد مربوط به همین کار در برنامه نت بینز استفاده کنی.
87852

mahdy_system
دوشنبه 15 خرداد 1391, 14:20 عصر
اقا یه دنیا ممنونم

فقط دو تا مشکل داشت

شماره ای رو نمیشه پاک کرد یا ویرایشش کرد

یعنی هم سرچ میکنه و هم اضافه می کنه

ولی پاک رو ویرایش رو که میزنی هیچ کاری انجام نمیده!

مشکل اون ها از کجا هستش؟

mortezaadi
دوشنبه 15 خرداد 1391, 16:51 عصر
بعد این خط optNewPhone.addActionListener(this);

این دو تا رو اضافه کن

optDeletePhone.addActionListener(this);
optUpdatePhone.addActionListener(this);


بعد تابع actionPerformed رو اینطوری تغییر بده:


public void actionPerformed(ActionEvent evt) {
Object source = evt.getSource();
if (source == optExit)
exitProgram();
else if (source == optNewPhone || source == btnNewPhone) {
NewPhone nf = new NewPhone(pb);
} else if (source == optPhoneList) {
ListPhones lf = new ListPhones(pb);
} else if (source == optSearch) {
SearchPhone sf = new SearchPhone(pb);
} else if (source== optDeletePhone){
DeletePhone df = new DeletePhone(pb);
} else if (source== optUpdatePhone){
UpdatePhone uf = new UpdatePhone(pb);
}

}



موفق باشی

mahdy_system
سه شنبه 16 خرداد 1391, 01:32 صبح
مرتضی جان خیلی خیلی ممنون ، البته بجای خط های
11 تا سیزده این توری نوشته بشه بهتره چون شکل های آپدیت و پاک کردن هم کار می کنه



} else if (source== optDeletePhone || source== btnDeletePhone ){
DeletePhone df = new DeletePhone(pb);
} else if (source== optUpdatePhone || source== btnUpdatePhone){


این رو برای بقیه دوستان گفتم تا اگر بخوان استفاده کنن کامل باشه :D


الان فقط فقط یه مشکل داره یعنی برنامه شماره اضافه می کنه، پاک میکنه، سرچ میکنه، لیست میکنه

فقط آپدیتش مشکل داره یه اسمی رو بخوای شمارش رو تغییر بدی تغییر نمیده!
زحمت اون رو هم بکشی (البته اگر وقت داری،من هم تا آخر هفته وقت دارم) واقعا ممنونت میشم

mortezaadi
سه شنبه 16 خرداد 1391, 13:43 عصر
البته جنبه آموزشی خوبی نداره
کلا برنامه ساختار Object oriented خوبی نداره encapsulation رعایت نشده اشیاء و کلاس ها به درستی مشخص نشده
از Api های جاوا به درستی استفاده نشده
مشکلات مهمتری هم داره همه لایه ها به درستی decouple نشدن در واقع لایه خاصی وجود نداره همه چیز درهمه و میتونست بجای ذخیره کل فایل از بافر ریدر استفاده کنه تا Performance بالاتر بره
ولی از بعضی لحاظ خوبه و میشه به عنوان یک پروژه دانشجویی چیزایی ازش درآورد.

در مجموع از ده نمره بهش 0.002 نمره میدم

تو کلاس UpdatePhone در تابع actionPerformed اینو جایگزین کنید مشکل اپدیت هم حل میشه.

public void actionPerformed(ActionEvent evt)
{
if ( evt.getSource() == b2 )
setVisible(false);
else
{
String name, phoneno;
char ptype;

phoneno = tf1.getText();
ptype = tf2.getText().charAt(0);

name = (String)jcbPhones.getSelectedItem();
int res = JOptionPane.showConfirmDialog(this,"Do you want to Update? " + name,
"Update",
JOptionPane.YES_NO_OPTION,
JOptionPane.QUESTION_MESSAGE);
if ( res == JOptionPane.YES_OPTION)
{
PhoneEntry entry = pb.getPhoneEntry(name);
entry.phoneno = phoneno;
entry.type = ptype;
pb.writeToDisk();

}

} // end of else

}

mahdy_system
سه شنبه 16 خرداد 1391, 21:53 عصر
آقا یه دنیا ممنون انشا الله از خدا هر چی میخوای بهت بده

خیلی گلی ;)