Could anyone explain me this part of code?
SampleFrame sampleFrame; public MyWindowAdapter(SampleFrame sampleFrame) { this.sampleFrame = sampleFrame; }
The actual code is: package applets; import java.awt.*; import java.awt.event.*; import java.applet.*; class SampleFrame extends Frame { SampleFrame(String title) { super(title); MyWindowAdapter adapter = new MyWindowAdapter(this); addWindowListener(adapter); } public void paint(Graphics g) { g.drawString("This is in frame window", 10, 40); } } class MyWindowAdapter extends WindowAdapter { SampleFrame sampleFrame; public MyWindowAdapter(SampleFrame sampleFrame) { this.sampleFrame = sampleFrame; } public void windowClosing(WindowEvent we) { sampleFrame.setVisible(false); } } public class AppletFrame extends Applet { Frame f; public void init() { f = new SampleFrame("A Frame Window"); f.setSize(250, 250); f.setVisible(true); } public void start() { f.setVisible(true); } public void stop() { f.setVisible(false);} public void paint(Graphics g) { g.drawString("This is in applet window", 10, 20); } }
sampleFrame is a variable of type SampleFrame. When an object of type MyWindowAdapter is created, MyWindowAdapter is passed an argument of type SampleFrame that will be called sampleFrame, inside the object! The constructor function assigns the SampleFrame passed in to the variable sampleFrame that belongs to this NEW object. It will be referred to as <the new MyWindowObject's name>.sampleFrame. The greater than less than stuff is just to surround changeable information.
Thank you :) @rsmith6559
You're welcome!
(:
Join our real-time social learning platform and learn together with your friends!