0

So I was making a Gui and I did the usual stuff, and I always do public Gui() {and have code in it}. what does it mean? Is it a constructor? What is it?

package tacos;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;


public class Gui extends JFrame{ 
private JTextField tf;
private JCheckBox boldbox;
private JCheckBox italicbox;

public Gui(){ //what does this public Gui thing mean?
    super("the title");
    setLayout(new FlowLayout());

    tf = new JTextField("this is a sentence", 20);
    tf.setFont(new Font("Serif",Font.PLAIN,14));
    add(tf);

    boldbox = new JCheckBox("bold");
    italicbox = new JCheckBox("italic");
    add(boldbox);
    add(italicbox);


    HandlerClass handler = new HandlerClass();
    boldbox.addItemListener(handler);
    italicbox.addItemListener(handler);



    }



}
Mureinik
  • 297,002
  • 52
  • 306
  • 350
frosty
  • 63
  • 1
  • 9

1 Answers1

1

Gui in your code is a constructor. It can be identified by the fact that it has the same name as the class and no return value.

Mureinik
  • 297,002
  • 52
  • 306
  • 350