LINK-LIST JAVA

xiaoxiao2021-03-06  41

Recently, the Java representation of the data structure (this is not good for C, I feel that it is possible to do graduation thesis, so I will learn) This is an example of a link-list, half graphic interface main.java is running Main class, listtest.java is a graphical interface, List.java is a list of primary code, Utility.java is used to store data I want to make the an actionListener as a Separating Class, But it doesn't work. So i make it it as a method .Main.javaimport javax.swing. *; Import java.awt. *; Import java.awt.event. *;

Public class main {public static void main (string [] args) {listtest listtest = new listtest (); listtest.init (); listtest.settitle ("link list"); listtest.setsize (400, 400); listtest.setVisible True);}}

Listtest.javaimport javax.swing. *; Import java.awt. *; Import java.awt.event. *; Import java.lang. *;

public class ListTest extends JFrame implements ActionListener {JButton addAtF, addAtB, delFrF, delFrB, print; JTextField input; JLabel display; JPanel p1, p2, p3, p4; Container container; Listener listener; public void init () {Listener listener = new Listener (); // list mylist = new list (); input = new jtextfield (35); display = new jlabel ("Result:"); jButton addatf = new jButton ("addatf"); jbutton addatb = new jbutton "addatb"); jButton Delfrf = new jbutton ("DelfRF"); jbutton delfrb = new jbutton ("DelfRb"); jPanel p1 = new jPanel (); jPanel p2 = new jPanel (); jPanel p2 = new JPANel (); jPanel p3 = new jPanel (); jPanel p4 = new jPanel (); container = getContentPane (); p1.add (input); p2.add (display); p3.add (addatf); p3.add (AddATB); P3.Add (DELFRF); P3.Add (DELFRB); P3.Add (Print); p4.Add (P1); p4.Add (p2); p4.Add (p3); container.add P4); addatf.addactionListener (this); addatb.addactionListener (this); D elFrF.addActionListener (this); delFrB.addActionListener (this); print.addActionListener (this); /*addAtF.addActionListener(listener); addAtB.addActionListener (listener); delFrF.addActionListener (listener); delFrB.addActionListener (listener) PRINT.ADDACTIONListener (Listener); * /}

Public List MyList; Public Void ActionPerformed (ActionEvent E) {list mylist = new list (); // jlabel display = new jlabel (); double = 100 * math.random (); int ranint = (int Ran; Integer Objint = new integer (ranint); string cmd = E.GetActionCommand (); if (cmd.equals ("addatf")) {if (MyUtility.count! = 0) for (int i = 0; i

} Else {int I = utility.count; myutility.rannum [i] = a; utility.count = uTility.count 1; //system.out.println ("s3");}}}

List.javaimport java. *;

public class List {private ListNode firstNode; private ListNode lastNode; private String name; public List (String s) {name = s; firstNode = lastNode = null;} public List () {this ( "list");} public void insertAtFront (Object insertItem) {if (isEmpty ()) firstNode = lastNode = new ListNode (insertItem); else firstNode = new ListNode (insertItem, firstNode);} public void insertAtBack (Object insertItem) {if (isEmpty ()) firstNode = lastNode = new ListNode (insertItem); else lastNode = lastNode.next = new ListNode (insertItem);} public Object delFromFront () throws EmptyListException {Object removeItem = null; if (isEmpty ()) throw new EmptyListException (name); removeItem = firstNode .data; if (firstNode.equals (lastNode)) firstNode = lastNode = null; else firstNode = firstNode.next; return removeItem;} public Object delFromBack () throws EmptyListException {Object removeItem = null; if (isEmpty ()) throw new EmptyListException (name); removeItem = lastNode.data; if (firstNode.equals (lastNode)) firstNode = lastNode = null; else {ListNode movePoObject = firstNode; while (movePoObject.next =! lastNode) movePoObject = movePoObject.next; lastNode = movePoObject; movePoObject.next = null;} return removeItem;} public boolean isEmpty () {return (firstNode == null);} public void print () {if (isEmpty ()) {System.out.Println ("Empty" Name); Return;} system.out.print ("

" Name " IS: "); ListNode Current = firstnode; while (current! = Null) {system.out.print (current.data); current = current.next;} system.out.println (); System.out.println ();} class ListNode {Object data; ListNode next; ListNode (Object o) {data = o; next = null;} ListNode (Object o, ListNode nextNode) {data = o; next = nextNode; } Object getnode () {return data;} ListNode getnext () {return next;}}

Class EmptyListexception Extends RuntimeException {public EmptyListexception (String Name) {Super ("THE" Name "IS EMPTY);}}

} UTility.javapublic class utility {public static int rannum [] = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 0, 0.0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}; public static int count = 0; public utility () {}}}

转载请注明原文地址:https://www.9cbs.com/read-78434.html

New Post(0)