最近在学习数据结构的java表示方法(本来C描述的就学不好,但觉得到时做毕业论文可能有用,所以就再学)
这是一个link-list的例子,半图形界面,但还没有调试成功。
Main.java是运行主类,ListTest.java是图形界面,List.java是链表主代码
Main.java
import 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.setSize (400,400);
listTest.setVisible (true);
}
}
ListTest.java
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.lang.*;
public class ListTest extends JFrame
{
PRivate JButton addAtF,addAtB,delFrF,delFrB,print;
private JTextField input;
private JLabel display;
private JPanel p1,p2,p3,p4;
private Container container;
private List myList;
Listener listener;
public void init()
{
Listener listener = new Listener();
List myList = new List();
JTextField input = new JTextField(35);
JLabel display = new JLabel("Result: ");
JButton addAtF = new JButton("addAtF");
JButton addAtB = new JButton("addAtB");
JButton delFrF = new JButton("delFrF");
JButton delFrB = new JButton("delFrB");
JButton print = new JButton("print");
JPanel p1 = 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(listener);
addAtB.addActionListener(listener);
delFrF.addActionListener(listener);
delFrB.addActionListener(listener);
print.addActionListener(listener);
}
class Listener implements ActionListener
{
public void actionPerformed( ActionEvent e)
{
double ran = 100 * Math.random();
int ranInt = (int)ran;
Integer objInt = new Integer(ranInt);
新闻热点
疑难解答