السلام عليكم
لدي مشروع مبسط باستخدام linked list حيث يقوم المستخدم بادخال بيانات الراكب ومن ثم يخزنها داخل لنك لست عندي مشكله في انه كلما ضغطت علي عمليه الاضافه واضفت راكب وحاولت طباعه كل الركاب كي اتاكد من ان البيانات داخل ال لنك ليست لا يظهر لي شي مما يجعلني افترض انه لا تدخل البيانات الي النود
ارجو مراجعه الكود وتوضيح اين الخطا وكيف اعالج هذه المشكله
علما ان البرنامج حاليا مكون من التالي
1- شاشه عرض المشروع
2- شاشه ادخال اسم وكلمه مرور مدير النظام اسم المستخدم هو rrr وكلمه السر r123
2- شاشه ادخال بيانات الراكب
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
public class AirplainSystem extends JFrame implements ActionListener {
/////********* Start AdminFrame Class*********/////////
JButton bEnter;
JButton bExit;
Login L=new Login();
public void MainFrame()
{
Container frame1=getContentPane();
// ********create new components *******
bEnter= new JButton("Enter");
bExit= new JButton("Exit");
JLabel L1=new JLabel("Yemenia Airlines Reservation System");
JLabel L2=new JLabel("created by mohammed");
JLabel LImg=new JLabel();
LImg.setIcon(new javax.swing.ImageIcon(".\\img\\y.jpg"));
//C:\\Documents and Settings\\All Users\\Documents\\My Pictures
JPanel p_main1=new JPanel();
JPanel p_main2=new JPanel();
JPanel p_main3=new JPanel();
// *********Add components to panels *********
p_main1.add(L1);
p_main1.setBackground(new Color(30,200,199));
p_main2.add(LImg);
p_main2.add(bEnter);
//
bEnter.addActionListener(this);
bExit.addActionListener(this);
p_main2.add(bExit);
p_main3.add(L2);
p_main3.setBackground(new Color(30,200,199));
// ********Add panels to the Frame********
frame1.add(p_main1,BorderLayout.NORTH);
frame1.add(p_main2,BorderLayout.CENTER);
frame1.add(p_main3,BorderLayout.SOUTH);
setSize(500,500);
setVisible(true);
}
// }
public void actionPerformed(ActionEvent e)
{
if (e.getSource()==bEnter)
{
L.setVisible(true);
setVisible(false);
}
if (e.getSource()==bExit)
{
//L.setVisible(true);
setVisible(false);
}
//System.out.println("sfdasfafaf");
}
/////********* End AdminFrame Class*********/////////
///////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////
public static void main(String arr[] )
{
AirplainSystem af=new AirplainSystem();
af.MainFrame();
//af.pa
}
}// End of AirPlain System classوهذا الكلاس الخاص بدخول مدير النظام
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
class Login extends JFrame implements ActionListener
{
Container mainContaner;
JButton chkAdmin;
JPanel AdminchkCard;
JLabel label1,label2;
JTextField text1,text2;
JPanel footer_pan;
JPanel header_pan;
GridBagLayout gb;
GridBagConstraints gbc;
JPanel mainCard;
passengerClass ap=new passengerClass();
//JPanel head;
public Login()
{
mainContaner=getContentPane();
mainContaner.setLayout(new BorderLayout());
label1 = new JLabel();
AdminchkCard=new JPanel();
label1.setText("Username:");
text1 = new JTextField(15);
label2 = new JLabel();
label2.setText("Password:");
text2 = new JPasswordField(15);
JLabel CreatedBy=new JLabel("created by mohammed",JLabel.CENTER);
JLabel YARS=new JLabel("Yemenia Airlines Reservation System",JLabel.CENTER);
footer_pan=new JPanel();
header_pan=new JPanel();
mainCard=new JPanel();
mainCard.setLayout(new CardLayout());
footer_pan.setBackground(new Color(30,200,199));
header_pan.setBackground(new Color(30,200,199));
header_pan.setLayout(new BorderLayout());
header_pan.add(CreatedBy);
footer_pan.setLayout(new BorderLayout());
footer_pan.add(YARS);
chkAdmin=new JButton("Check");
// centr_pan=new JPanel(new CardLayout());
//MainPanCard.setLayout(AddCardLout);
//
//Add_pan.setLayout(gb);
gb=new GridBagLayout();
gbc=new GridBagConstraints();
gbc.insets=new Insets(2,2,2,2);
AdminchkCard.setLayout(gb);
gbc.gridy=0;
gbc.gridx=0;
gbc.anchor=GridBagConstraints.EAST;
gbc.fill=GridBagConstraints.NONE;
gb.setConstraints(label1,gbc);
gbc.gridx=1;
gbc.anchor=GridBagConstraints.WEST;
gbc.fill=GridBagConstraints.NONE;
gb.setConstraints(text1,gbc);
gbc.gridy=1;
gbc.gridx=0;
gbc.anchor=GridBagConstraints.EAST;
gbc.fill=GridBagConstraints.NONE;
gb.setConstraints(label2,gbc);
gbc.gridx=1;
gbc.anchor=GridBagConstraints.WEST;
gbc.fill=GridBagConstraints.NONE;
gb.setConstraints(text2,gbc);
gbc.gridy=2;
gbc.gridx=1;
gbc.anchor=GridBagConstraints.EAST;
gbc.fill=GridBagConstraints.NONE;
gb.setConstraints(chkAdmin,gbc);
mainContaner.add(header_pan,BorderLayout.NORTH);
mainContaner.add(footer_pan,BorderLayout.SOUTH);
AdminchkCard.add(label1);
AdminchkCard.add(text1);
AdminchkCard.add(label2);
AdminchkCard.add(text2);
AdminchkCard.add(chkAdmin);
mainCard.add("1",AdminchkCard);
mainContaner.add(mainCard);
chkAdmin.addActionListener(this);
setTitle("LOGIN FORM");
setSize(400,400);
}
public void actionPerformed(ActionEvent ae)
{
String value1=text1.getText();
String value2=text2.getText();
if (value1.equals("rrr") && value2.equals("r123")) {
/*.out.println("enter the valid username and password");
JOptionPane.showMessageDialog(this,"Ok u can start ",
"Error",JOptionPane.ERROR_MESSAGE); */
ap.setVisible(true);
setVisible(false);
}
else{
System.out.println("enter the valid username and password");
JOptionPane.showMessageDialog(this,"Incorrect login or password",
"Error",JOptionPane.ERROR_MESSAGE);
text1.setText("");
text2.setText("");
}
}
}
/*class LoginDemo
{
public static void main(String arg[])
{
try
{
Login frame=new Login();
frame.setSize(300,100);
frame.setVisible(true);
}
catch(Exception e)
{JOptionPane.showMessageDialog(null, e.getMessage());}
}*/
//}اما هذا فهو الكلاس الخاص دوال ابستراكت
public abstract class MyAbstractList implements MyList {
protected int size = 0; // The size of the list
/** Create a default list */
protected MyAbstractList() {
}
/** Create a list from an array of objects */
protected MyAbstractList(Object[] objects) {
for (int i = 0; i < objects.length; i++)
this.add(objects);
}
/** Add a new element o at the end of this list */
public void add(Object o) {
add(size, o);
}
/** Return true if this list contains no elements */
public boolean isEmpty() {
return size == 0;
}
/** Return the number of elements in this list */
public int size() {
return size;
}
/** Remove the first occurrence of the element o from this list.
* Shift any subsequent elements to the left.
* Return true if the element is removed. */
public boolean remove(Object o) {
if (indexOf(o) >= 0) {
remove(indexOf(o));
return true;
}
else
return false;
}
}اما هذا كلاس خاص اللنك لست
public class MyLinkedList extends MyAbstractList {
private Node first, last;
/** Create a default list */
public MyLinkedList() {
}
/** Create a list from an array of objects */
public MyLinkedList(Object[] objects) {
super(objects);
}
/** Return the first element in the list */
public Object getFirst() {
if (size == 0) return null;
else return first.element;
}
/** Return the last element in the list */
public Object getLast() {
if (size == 0) return null;
else return last.element;
}
/** Add an element to the beginning of the list */
public void addFirst(Object o) {
Node newNode = new Node(o);
newNode.next = first;
first = newNode;
size++;
if (last == null)
last = first;
}
/** Add an element to the end of the list */
public void addLast(Object o) {
if (last == null) {
first = last = new Node(o);
}
else {
last.next = new Node(o);
last = last.next;
}
size++;
}
/** Adds a new element o at the specified index in this list
* The index of the first element is 0 */
public void add(int index, Object o) {
if (index == 0) addFirst(o);
else if (index >= size) addLast(o);
else {
Node current = first;
for (int i = 1; i < index; i++)
current = current.next;
Node temp = current.next;
current.next = new Node(o);
(current.next).next = temp;
size++;
}
}
/** Remove the first node and
* return the object that is contained in the removed node. */
public Object removeFirst() {
if (size == 0) return null;
else {
Node temp = first;
first = first.next;
size--;
if (first == null) last = null;
return temp.element;
}
}
/** Remove the last node and
* return the object that is contained in the removed node. */
public Object removeLast() {
// Implementation left as an exercise
return null;
}
/** Removes the element at the specified position in this list.
* Returns the element that was removed from the list. */
public Object remove(int index) {
if ((index < 0) || (index >= size)) return null;
else if (index == 0) return removeFirst();
else if (index == size - 1) return removeLast();
else {
Node previous = first;
for (int i = 1; i < index; i++) {
previous = previous.next;
}
Node current = previous.next;
previous.next = current.next;
size--;
return current.element;
}
}
/** Override toString() to return elements in the list */
public void PrintString() {
StringBuffer result = new StringBuffer();
Node current = first;
for (int i = 0; i < size; i++) {
result.append(current.element);
current = current.next;
// if (current != null)
// result.append(","); // Separate two elements with a comma
// 115 else
// 116 result.append("]"); // Insert the closing ] in the string
}
System.out.print(result.toString());
// return result.toString();
}
/** Clear the list */
public void clear() {
first = last = null;
}
/** Return true if this list contains the element o */
public boolean contains(Object o) {
// Implementation left as an exercise
return true;
}
/** Return the element from this list at the specified index */
public Object get(int index) {
// Implementation left as an exercise
return null;
}
/** Returns the index of the first matching element in this list.
* Returns -1 if no match. */
public int indexOf(Object o) {
// Implementation left as an exercise
return 0;
}
/** Returns the index of the last matching element in this list
* Returns -1 if no match. */
public int lastIndexOf(Object o) {
// Implementation left as an exercise
return 0;
}
/** Replace the element at the specified position in this list
* with the specified element. */
public Object set(int index, Object o) {
// Implementation left as an exercise
return null;
}
private static class Node {
Object element;
Node next;
public Node(Object o) {
element = o;
}
}
}هذا انترفيس كلاس
public interface MyList {
/** Add a new element o at the end of this list */
public void add(Object o);
/** Add a new element o at the specified index in this list */
public void add(int index, Object o);
/** Clear the list */
public void clear();
/** Return true if this list contains the element o */
public boolean contains(Object o);
/** Return the element from this list at the specified index */
public Object get(int index);
/** Return the index of the first matching element in this list.
* Return -1 if no match. */
public int indexOf(Object o);
/** Return true if this list contains no elements */
public boolean isEmpty();
/** Return the index of the last matching element in this list
* Return -1 if no match. */
public int lastIndexOf(Object o);
/** Remove the first occurrence of the element o from this list.
* Shift any subsequent elements to the left.
* Return true if the element is removed. */
public boolean remove(Object o);
/** Remove the element at the specified position in this list
* Shift any subsequent elements to the left.
* Return the element that was removed from the list. */
public Object remove(int index);
/** Replace the element at the specified position in this list
* with the specified element and return the new set. */
public Object set(int index, Object o);
/** Return the number of elements in this list */
public int size();
}اما هذا الكلاس فهو خاص الباسنجر
public class Passenger {
String PNa;
String FromCity;
String ToCity;
String DepDate;
String ArriveDate;
int NoAdults;
int NoChild;
int PId;
Passenger(){};
public Passenger(int PId,String PNa,String From,String To,String Ddate,String Adate,int Ano,int chNo )
{
}
public void PInfo(){
System.out.println(PId+" "+PNa+" "+NoAdults+" "+ToCity+" "+FromCity+" "+NoAdults+" "+ NoChild+" ");
}
}اخيرا الواجهه الخاصه بالادخال
import java.awt.BorderLayout;
import java.awt.CardLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Container;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Date;
import javax.swing.*;
public class passengerClass extends JFrame implements ActionListener
{
public MyLinkedList plist;
public int PassId;
public int index=0;
//public Passenger passengerInfo[];
//declar passenger calss
Container mainContaner;
Passenger Psg;
JMenuItem NewPa;
JMenuItem Exit;
// JMenuItem RemoveFirst;
JMenuItem Removeitem;
//JMenuItem AddLast;
JMenuItem Additem;
JMenuItem PrintAll;
JButton Add;
JButton Remove;
JTextField PassNa;
JComboBox CityFrom;
JComboBox CityTo;
JComboBox Depart;
JComboBox arrive;
JComboBox Adults;
JComboBox Child;
JLabel CreatedBy;
JLabel YARS;
JPanel footer_pan;
JPanel header_pan;
JPanel MainPanCard;
JPanel Add_pan;
CardLayout AddCardLout;
GridBagLayout gb;
GridBagConstraints gbc;
Object removeobject;
///////////////////////////////////////////////////
public passengerClass ()
{
Psg=new Passenger();
plist=new MyLinkedList();
PassId=1;
setTitle("Reservation Details");
mainContaner=getContentPane();
mainContaner.setLayout(new BorderLayout());
JMenuBar jmb = new JMenuBar();// create menu bar
MainPanCard=new JPanel();
Add_pan=new JPanel();
AddCardLout=new CardLayout();
gb=new GridBagLayout();
gbc=new GridBagConstraints();
gbc.insets=new Insets(2,2,2,2);
CreatedBy=new JLabel("created by Rifat mohammed",JLabel.CENTER);
YARS=new JLabel("Yemenia Airlines Reservation System");
footer_pan=new JPanel();
header_pan=new JPanel();
footer_pan.setBackground(new Color(30,200,199));
header_pan.setBackground(new Color(30,200,199));
MainPanCard.setLayout(AddCardLout);
Add_pan.setLayout(gb);
// ************* define menu Components
JMenu fileMenu = new JMenu("File");// create File menu
NewPa= new JMenuItem("New");
NewPa.addActionListener(this);
fileMenu.add(NewPa);
Exit= new JMenuItem("Exit");
fileMenu.add(Exit);
JMenu Insert = new JMenu("Add");// create File menu
// AddLast= new JMenuItem("Add Last");
// AddLast.addActionListener(this);
// Insert.add(AddLast);
Additem= new JMenuItem("Add passenger");
Additem.addActionListener(this);
Insert.add(Additem);
JMenu EditeMenu = new JMenu("Edit");// create Edit menu
EditeMenu.setMnemonic('E');
//JMenu Remov= new JMenu("Remove");
Removeitem = new JMenuItem("Remove");
// JMenuItem RemoveLast = new JMenuItem("RemoveLast");
// Remov.add(RemoveFirst);
//Remov.add(Removeitem);
EditeMenu.add(Removeitem);
JMenuItem Update = new JMenuItem("Update");
// EditeMenu.add(DeletePs);
EditeMenu.add(Update);
JMenu search = new JMenu("Search");
JRadioButtonMenuItem Search_Na=new JRadioButtonMenuItem("By Name");
JRadioButtonMenuItem Search_Id=new JRadioButtonMenuItem("By Id");
search.add(Search_Na);
search.add(Search_Id);
JMenu PrintInfo = new JMenu("Print");
PrintAll = new JMenuItem("Print All");
PrintAll.addActionListener(this);
PrintInfo.add(PrintAll);
//*******************************************************
//***** panel Add_pan components
JLabel LWelcom=new JLabel("yemeina Airlines");
JLabel LPassNa=new JLabel("Passenger Name");
PassNa=new JTextField(15);
JLabel LFrom=new JLabel("From ",JLabel.CENTER);
JLabel LTo=new JLabel("To",JLabel.CENTER);
JLabel LDate=new JLabel("From",JLabel.CENTER);
CityFrom = new JComboBox();
CityTo=new JComboBox();
JLabel LDepart=new JLabel("Depart Date",JLabel.CENTER);
Depart=new JComboBox();
JLabel LArrive=new JLabel("Arrive Date",JLabel.CENTER);
arrive=new JComboBox();
JLabel LTravelres=new JLabel("Travelres",JLabel.CENTER);
Adults = new JComboBox();
JLabel Ladults = new JLabel ("Adults",JLabel.CENTER);
JLabel Lchild = new JLabel ("Childern",JLabel.CENTER);
Child = new JComboBox();
Add = new JButton ("Add");
Remove = new JButton ("Remove");
Add.addActionListener(this);
Remove.addActionListener(this);
CityFrom.addItem("Sanaa");
CityFrom.addItem("Egypt");
CityFrom.addItem("Sa");
CityFrom.addItem("USE");
CityFrom.addItem("Jordan");
CityFrom.addItem("Iraq");
CityTo.addItem("Aden");
CityTo.addItem("Egypt");
CityTo.addItem("Malysia");
CityTo.addItem("Turkiya");
CityTo.addItem("USA");
CityTo.addItem("Sa");
Adults.addItem("1");
Adults.addItem("2");
Adults.addItem("3");
Adults.addItem("4");
Adults.addItem("5");
Child.addItem("0");
Child.addItem("1");
Child.addItem("2");
Child.addItem("3");
Child.addItem("4");
gbc.gridy=0;
gbc.gridx=0;
gbc.anchor=GridBagConstraints.EAST;
gbc.fill=GridBagConstraints.NONE;
gb.setConstraints(LPassNa,gbc);
gbc.gridx=1;
gbc.anchor=GridBagConstraints.WEST;
gbc.fill=GridBagConstraints.NONE;
gb.setConstraints(PassNa,gbc);
gbc.gridy=1;
gbc.gridx=0;
gbc.anchor=GridBagConstraints.EAST;
gbc.fill=GridBagConstraints.NONE;
gb.setConstraints(LFrom,gbc);
gbc.gridx=1;
gbc.anchor=GridBagConstraints.WEST;
gbc.fill=GridBagConstraints.NONE;
gb.setConstraints(CityFrom,gbc);
gbc.gridx=1;
gbc.anchor=GridBagConstraints.EAST;
gbc.fill=GridBagConstraints.NONE;
gb.setConstraints(LTo,gbc);
gbc.gridx=2;
gbc.anchor=GridBagConstraints.WEST;
gbc.fill=GridBagConstraints.NONE;
gb.setConstraints(CityTo,gbc);
gbc.gridx=0;
gbc.gridy=2;
gbc.anchor=GridBagConstraints.EAST;
gbc.fill=GridBagConstraints.NONE;
gb.setConstraints(LDepart,gbc);
gbc.gridx=1;
gbc.anchor=GridBagConstraints.WEST;
gbc.fill=GridBagConstraints.NONE;
gb.setConstraints(Depart,gbc);
gbc.gridx=1;
gbc.anchor=GridBagConstraints.EAST;
gbc.fill=GridBagConstraints.NONE;
gb.setConstraints(LArrive,gbc);
gbc.gridx=2;
gbc.anchor=GridBagConstraints.WEST;
gbc.fill=GridBagConstraints.NONE;
gb.setConstraints(arrive,gbc);
gbc.gridx=0;
gbc.gridy=3;
gbc.anchor=GridBagConstraints.EAST;
gbc.fill=GridBagConstraints.NONE;
gb.setConstraints(Ladults,gbc);
gbc.gridx=1;
gbc.anchor=GridBagConstraints.WEST;
gbc.fill=GridBagConstraints.NONE;
gb.setConstraints(Adults,gbc);
gbc.gridx=1;
gbc.anchor=GridBagConstraints.EAST;
gbc.fill=GridBagConstraints.NONE;
gb.setConstraints(Lchild,gbc);
gbc.gridx=2;
gbc.anchor=GridBagConstraints.WEST;
gbc.fill=GridBagConstraints.NONE;
gb.setConstraints(Child,gbc);
gbc.gridy=4;
gbc.gridx=1;
gbc.anchor=GridBagConstraints.WEST;
gbc.fill=GridBagConstraints.NONE;
gb.setConstraints(Add,gbc);
gbc.gridy=4;
gbc.gridx=2;
gbc.anchor=GridBagConstraints.WEST;
gbc.fill=GridBagConstraints.NONE;
gb.setConstraints(Remove,gbc);
//*********** End Add_pan *****************
/////////////////////////////////////////////////////////////////////////
// Add menu to menu bar
jmb.add(fileMenu);
jmb.add(Insert);
jmb.add(EditeMenu);
jmb.add(search);
jmb.add(PrintInfo);
//**************************************************
Add_pan.add(LPassNa);
Add_pan.add(PassNa);
Add_pan.add(LFrom);
Add_pan.add(CityFrom);
Add_pan.add(LTo);
Add_pan.add(CityTo);
Add_pan.add(LDepart);
Add_pan.add(Depart);
Add_pan.add(LArrive);
Add_pan.add(arrive);
Add_pan.add(Ladults);
Add_pan.add(Adults);
Add_pan.add(Lchild);
Add_pan.add(Child);
Add_pan.add(Add);
Add_pan.add(Remove);
MainPanCard.add("1",Add_pan);
mainContaner.add(MainPanCard,BorderLayout.CENTER);
mainContaner.add(CreatedBy,BorderLayout.SOUTH);
footer_pan.add(CreatedBy);
mainContaner.add(footer_pan,BorderLayout.SOUTH);
header_pan.add(YARS);
mainContaner.add(header_pan,BorderLayout.NORTH);
//*************************************************
setJMenuBar(jmb);
setSize(400, 400);
//setVisible(true);
}
public void actionPerformed(ActionEvent e){
Object src=e.getSource();
if (src==Add)
// if (src==Add) ot (src=additem)
{
Psg.PId=++PassId;
Psg.PNa=PassNa.getText();
Psg.FromCity= (String) CityFrom.getSelectedItem();
Psg.ToCity=(String) CityTo.getSelectedItem();
//Psg.DepDate=(Date) Depart.getSelectedItem();
//Psg.ArriveDate=(Date) arrive.getSelectedItem();
Psg.NoAdults=Integer.parseInt((String) Adults.getSelectedItem());
Psg.NoChild=Integer.parseInt((String) Child.getSelectedItem());
plist.add(Psg);
++index;
plist.PrintString();
if (src==PrintAll)
{
plist.PrintString();
}
/* if (src==Remove)
{
removeobject=plist.removeFirst();
// plist.printInfo();
}
if(src==NewPa)
{
PassNa.setText("");
}
*/
}
/* public static void main(String[] arg)
{
//AdminCheck Achk = new AdminCheck();
passengerClass teks = new passengerClass();
teks.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
*/
}}