0% found this document useful (0 votes)
37 views2 pages

JAVA Tuto2021-2022

The document contains code for creating a GUI login interface in Java using Swing. It includes code for creating text fields for username and password, buttons to connect or cancel, and panels to organize the layout. The code demonstrates creating Swing components, setting layouts, adding action listeners, and packaging the frame.

Uploaded by

massablaisetamfu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
37 views2 pages

JAVA Tuto2021-2022

The document contains code for creating a GUI login interface in Java using Swing. It includes code for creating text fields for username and password, buttons to connect or cancel, and panels to organize the layout. The code demonstrates creating Swing components, setting layouts, adding action listeners, and packaging the frame.

Uploaded by

massablaisetamfu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

Exercise 1: GUI- in JAVA

public class Authentification extends JFrame implements


ActionListener { //pan1 contient le nom de l'entreprise
JTextField login; pan1=new JPanel(new FlowLayout());
JPasswordField motpass= new JPasswordField (); pan1.add(label);
//pan2 contient tous les autres champs
JButton connexion,annuler; JLabel log=new JLabel("Username : ");
public Authentification(){ JLabel mot=new JLabel("Password : ");
super("Identification"); //(1) pan2=new JPanel(new FlowLayout());
this.setPreferredSize(new Dimension(400,250)); pan2.add(new JLabel(" "));
JPanel pan1, pan2; //(2) pan2.setLayout(new FlowLayout());
pan2.add(log);
login=new JTextField(); pan2.add(login);
pan2.add(mot);
connexion=new JButton("Connection"); pan2.add(motpass);
connexion.setActionCommand("connexion"); pan2.add(connexion);
connexion.addActionListener(this); pan2.add(annuler);
this.getContentPane().add(pan3);
annuler=new JButton("Cancel"); this.setResizable(false);
annuler.setActionCommand("annuler");//(3) pack();
annuler.addActionListener(this); }
annuler.setPreferredSize(new Dimension(98,20)); }

The following source code creates an interface to sign in to the system.

1. Explain the line: public class Authentification extends JFrame implements


ActionListener {
2. What class allows creating the text input field in JAVA SWING? What variables
contain the input field for “Password” and “Login”?
3. What are the uses of the variables of line (2)?
4. A panel in JAVA can have different layouts to present his components; state 04
layouts used in JAVA.
5. In this example which layout is been used for the panels?
6. Draw the output of this source code
7. What does the line (3), can it be applied on a text field instead of a button?
8. Write the instruction to create a button with the text on it “Validate”.

Exercise 2 General Knowledge

1. Explain the following: JAVA is an Object Oriented Programming Language


2. What library is used to build GUI in JAVA?
3. Describe the following characteristics concerning JAVA: Dynamic, robust, object
oriented.

1/2
4. What are the popular JAVA programming IDE?
5. How do we implement the inheritance in JAVA?
Exercise 3/

import java.io.*;
public class Employee {

// salary variable is a private static variable


private static double salary;

// DEPARTMENT is a constant
public static final String DEPARTMENT = "Development ";
int S = 0;
public static void main(String args[]) {
salary = 1000;
for (int i= 0; i<10 ; i= i+2) {
S += i;
}
System.out.println(DEPARTMENT + "average salary:" + salary);
}

1. What are the values of S and i at the end of the loop?


2. What are the meanings of the keywords private, public and static used in this code?
3. What are the attributes and methods of this JAVA class?
4. Declare the default constructor for this class.

2/2

You might also like