Java badge accumulation (constructor)

xiaoxiao2021-03-06  140

I just started learning Java, I saw Swing chapter, I wrote a small Java program, as follows:

//Test.javaimport javax.swing. *; Import java.awt. *; Import java.awt.event. *;

public class Test extends JFrame implements ActionListener {JButton btnOK; public void Test () {btnOK = new JButton ( "OK"); btnOK.addActionListener (this);. getContentPane () add (btnOK); setDefaultCloseOperation (JFrame.EXIT_ON_CLOSE); SetBounds (100, 100, 300, 130); setvisible (TRUE);} public void actionPerformed (AE.GetActionCommand (). Equals ("ok") SYSTEM PUBLIC Static void main (string [] args) {test t = new test ();}}

A tiny error is the definition of the constructor, and instantiated objects in the main function is requested to return an object handle, but if the return type of the constructor is defined as Void (no type), the instantiation failed, the program There is no error in compilation, just can't play any effect, learn C is equal to no learning, such a mistake can be made, so the pen is left here, remind himself! ! !

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

New Post(0)