Machan me java eke...me podi window ekaka open wena (receipt button click karana) output eka me main window eke black text area ekata ganne koamda ? 



Small window eke code eka
package com.perisic.peripherals;
import java.awt.Color;
import javax.swing.*;
import com.perisic.beds.PrinterInterface;
/*
* Displays text in a frame.
*/
public class BlueDisplay extends JFrame implements PrinterInterface {
/**
* A serialVersionUID is required by the JFrame class.
*/
private static final long serialVersionUID = -8505887234618184162L;
private JTextArea outputWindow;
/*
* when constructed the display will be directly visible.
*/
public BlueDisplay() {
super();
setSize(200, 600);
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
outputWindow = new JTextArea();
outputWindow.setForeground(Color.BLUE);
outputWindow.setBackground(Color.YELLOW);
getContentPane().add(outputWindow);
setVisible(true);
}
/*
* Prints the text str to the screen. Any previous text will be overwritten.
* @see com.perisic.beds.PrinterInterface#print(java.lang.String)
*/
public void print(String str) {
outputWindow.setText(str);
outputWindow.repaint();
}
}
Main window code
package com.perisic.peripherals;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
import com.perisic.beds.CustomerPanel;
/**
* A Simple Graphical User Interface for the Recycling Machine.
*
*
*/
public class RecyclingGUI extends JFrame implements ActionListener {
public void actionPerformed(ActionEvent e) {
// System.out.println("Received: e.getActionCommand()="+e.getActionCommand()+
// " e.getSource()="+e.getSource().toString() );
if(e.getSource().equals(slot1) ) {
myCustomerPanel.itemReceived(1);
} else if( e.getSource().equals(slot2)) {
myCustomerPanel.itemReceived(2);
} else if( e.getSource().equals(slot3)) {
myCustomerPanel.itemReceived(3);
} else if( e.getSource().equals(receipt)) {
myCustomerPanel.printReceipt();
}
}
JButton slot1 = new JButton("can");
JButton slot2 = new JButton("bottle");
JButton slot3 = new JButton("Slot 3");
JButton receipt = new JButton("Receipt");
CustomerPanel myCustomerPanel = new CustomerPanel(new BlueDisplay());
public RecyclingGUI() {
super();
setSize(400, 100);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel panel = new JPanel();
panel.add(slot1);
panel.add(slot2);
panel.add(slot3);
slot1.addActionListener(this);
slot2.addActionListener(this);
slot3.addActionListener(this);
panel.add(receipt);
receipt.addActionListener(this);
JTextArea outputWindow = new JTextArea(60,70);
outputWindow.setForeground(Color.green);
outputWindow.setBackground(Color.black);
setVisible(true);
panel.add(outputWindow);
getContentPane().add(panel);
panel.repaint();
}
public static void main(String [] args ) {
RecyclingGUI myGUI = new RecyclingGUI();
myGUI.setVisible(true);
}
}




Small window eke code eka
package com.perisic.peripherals;
import java.awt.Color;
import javax.swing.*;
import com.perisic.beds.PrinterInterface;
/*
* Displays text in a frame.
*/
public class BlueDisplay extends JFrame implements PrinterInterface {
/**
* A serialVersionUID is required by the JFrame class.
*/
private static final long serialVersionUID = -8505887234618184162L;
private JTextArea outputWindow;
/*
* when constructed the display will be directly visible.
*/
public BlueDisplay() {
super();
setSize(200, 600);
setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
outputWindow = new JTextArea();
outputWindow.setForeground(Color.BLUE);
outputWindow.setBackground(Color.YELLOW);
getContentPane().add(outputWindow);
setVisible(true);
}
/*
* Prints the text str to the screen. Any previous text will be overwritten.
* @see com.perisic.beds.PrinterInterface#print(java.lang.String)
*/
public void print(String str) {
outputWindow.setText(str);
outputWindow.repaint();
}
}
Main window code
package com.perisic.peripherals;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.*;
import com.perisic.beds.CustomerPanel;
/**
* A Simple Graphical User Interface for the Recycling Machine.
*
*
*/
public class RecyclingGUI extends JFrame implements ActionListener {
public void actionPerformed(ActionEvent e) {
// System.out.println("Received: e.getActionCommand()="+e.getActionCommand()+
// " e.getSource()="+e.getSource().toString() );
if(e.getSource().equals(slot1) ) {
myCustomerPanel.itemReceived(1);
} else if( e.getSource().equals(slot2)) {
myCustomerPanel.itemReceived(2);
} else if( e.getSource().equals(slot3)) {
myCustomerPanel.itemReceived(3);
} else if( e.getSource().equals(receipt)) {
myCustomerPanel.printReceipt();
}
}
JButton slot1 = new JButton("can");
JButton slot2 = new JButton("bottle");
JButton slot3 = new JButton("Slot 3");
JButton receipt = new JButton("Receipt");
CustomerPanel myCustomerPanel = new CustomerPanel(new BlueDisplay());
public RecyclingGUI() {
super();
setSize(400, 100);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
JPanel panel = new JPanel();
panel.add(slot1);
panel.add(slot2);
panel.add(slot3);
slot1.addActionListener(this);
slot2.addActionListener(this);
slot3.addActionListener(this);
panel.add(receipt);
receipt.addActionListener(this);
JTextArea outputWindow = new JTextArea(60,70);
outputWindow.setForeground(Color.green);
outputWindow.setBackground(Color.black);
setVisible(true);
panel.add(outputWindow);
getContentPane().add(panel);
panel.repaint();
}
public static void main(String [] args ) {
RecyclingGUI myGUI = new RecyclingGUI();
myGUI.setVisible(true);
}
}