OOP in JAVA
OOP in JAVA
JButton connexion,annuler;
public Authentification(){
super("Identification"); //(1)
this.setPreferredSize(new Dimension(400,250));
connexion.setActionCommand("connexion");
connexion.addActionListener(this);
annuler=new JButton("Cancel");
annuler.setActionCommand("annuler");//(3)
annuler.addActionListener(this);
annuler.setPreferredSize(new Dimension(98,20));
//pan1 contient le nom de l'entreprise
pan1.add(label);
pan2.setLayout(new FlowLayout());
pan2.add(log);
pan2.add(login);
pan2.add(mot);
pan2.add(motpass);
pan2.add(connexion);
pan2.add(annuler);
this.getContentPane().add(pan3);
this.setResizable(false);
pack();
}
}
2. What class allows creating the text input field in JAVA SWING? What variables
contain the input field for “Password” and “Login”?
The `JTextField` class is used to create text input fields in
Java Swing.
In the provided code:
The `JTextField` variable `login` represents the input
field for the login username.
The `JPasswordField` variable `motpass` represents the
input field for the password. `JPasswordField` is used
specifically for password input fields to mask the
entered characters.
2. What are the uses of the variables of line (2)?
`login`: Represents the text input field where users enter
their username or login information.
`motpass`: Represents the password input field where users
enter their password.
`connexion`: Represents the button used to initiate the login
or connection process.
`annuler`: Represents the button used to cancel or reset the
login process.
4. A panel in JAVA can have different layouts to present his components; state 04
7. What does the line (3), can it be applied on a text field instead of a button?
Line (3) sets the action command for the "Cancel" button
(`annuler`). When this button is clicked, an action event
with the command "annuler" will be generated.
This line cannot be directly applied to a text field because
text fields do not directly generate action events like
buttons do. However, text fields can be associated with
action listeners to respond to different types of events,
such as text input or focus changes.
class Animal {
void sound() {
void sound() {
System.out.println("Dog barks");
In this example, the `Dog` class inherits from the `Animal` class,
and the `sound()` method is overridden in the `Dog` class to
provide a specific behavior for dogs.
Exercise 3
import java.io.*;
int S = 0;
public static void main(String args[]) {
salary = 1000;
S += i;
}
System.out.println(DEPARTMENT + "average salary:" + salary);
2. What are the meanings of the keywords private, public and static used in this code?
private: it is an access modifier that restricts access to
the variable or method to within the same class. In this
code, “private static void double salary” declares a private
‘salary’ accessible only within the ‘Employee’ class
public: it is an access modifier that allows access to the
variable or method from any other class. In this code,
‘public static final String DEPARTMENT = “Development;”
declares a public static final variable, ‘Department’
accessible from any class