从不同的类添加JTextArea

时间:2017-12-02 21:57:09

标签: java arrays swing queue

嗨,大家好,当我运行我的代码时,它可以工作但我需要帮助显示我的System.out.println(数据+“添加到队列中”);在JTextArea(txt1)可以有人帮我需要这个,我一直试图做它不工作所以,我需要帮助谢谢你的家伙

private Node front, rear;
private int currentSize;
MainFrame main = new MainFrame();

private class Node {

    int data;
    Node next;
}

public deneme2() {
    front = null;
    rear = null;
    currentSize = 0;
}

public boolean isEmpty() {
    return (currentSize == 0);
}

public int dequeue() {
    int data = front.data;
    front = front.next;
    if (isEmpty()) {
        rear = null;
    }
    currentSize--;
    System.out.println(data + " removed from the queue");

    return data;
}

public void enqueue(int data) {
    Node oldRear = rear;
    rear = new Node();
    rear.data = data;
    rear.next = null;
    if (isEmpty()) {
        front = rear;
    } else {
        oldRear.next = rear;
    }
    currentSize++;
    System.out.println(data + " added to the queue");
}

public static void main(String a[]) throws FileNotFoundException {

    Scanner s = new Scanner(new File("list.txt"));
    deneme2 queue = new deneme2();
    while (s.hasNext()) {
        queue.enqueue(s.nextInt());
    }
    s.close();
    queue.dequeue();
    SwingUtilities.invokeLater(new Runnable() {
        @Override
        public void run() {
            new MainFrame();

        }
    });

} }

公共类MainFrame扩展了JFrame {

public MainFrame() {

 JFrame frame=new JFrame();  
 JButton b1=new JButton("Load Up the Que");
 JButton b2=new JButton("Add to the Que");
 JTextArea txt1=new JTextArea();



 JTextArea txt2=new JTextArea();
 txt1.setEditable(false);

 b1.setBounds(50,100,180, 100); 
 b2.setBounds(50,300,180, 100);
 txt1.setBounds(600,100, 300,600);
 txt2.setBounds(300,300, 180,100);


 frame.add(b1);  
 frame.add(b2);  
 frame.add(txt1);
 frame.add(txt2);
 frame.setLayout(null); 
 frame.setSize(1000, 1500);
 frame.setVisible(true);
 frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

}

}

0 个答案:

没有答案