Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
A
alx_mszczonow_1
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Patryk Czarnik
alx_mszczonow_1
Commits
a47a3707
Commit
a47a3707
authored
Jul 24, 2023
by
Patryk Czarnik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rozmowa - Witaj imię
parent
6510d74a
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
1 deletions
+19
-1
Rozmowa1.java
src/main/java/swing/zdarzenia/Rozmowa1.java
+19
-1
No files found.
src/main/java/swing/zdarzenia/Rozmowa1.java
View file @
a47a3707
...
...
@@ -2,6 +2,8 @@ package swing.zdarzenia;
import
javax.swing.*
;
import
java.awt.*
;
import
java.awt.event.ActionEvent
;
import
java.awt.event.ActionListener
;
public
class
Rozmowa1
{
private
static
final
Font
FONT
=
new
Font
(
"Arial"
,
Font
.
BOLD
,
32
);
...
...
@@ -61,7 +63,23 @@ public class Rozmowa1 {
MojListener
listener
=
new
MojListener
();
guzik
.
addActionListener
(
listener
);
// W praktyce obsługę zdarzeń zapisuje się w obiektach tworzonych na zasadzie "kalasy anonimowej".
// Dzięki temu mamy ułatwiony dostęp do komponentów okna, poprzez zmienne z tej klasy, w ktrej jesteśmy.
guzik
.
addActionListener
(
new
ActionListener
()
{
public
void
actionPerformed
(
ActionEvent
evt
)
{
String
imie
=
pole
.
getText
();
powitanie
.
setText
(
"Witaj "
+
imie
);
powitanie
.
setForeground
(
Color
.
BLUE
);
}
});
// Od Javy 8 w niektórych przypadkach (gdy interfejs zawiera tylko jedną metodę) można też użyć wyrażeń lambda.
// Tutaj dodam obsługę zdarzenia do pola tekstowego - zostanie to wykonane, gdy uzytkownik w polu tekstowym naciśnie enter.
pole
.
addActionListener
((
evt
)
->
{
String
imie
=
pole
.
getText
();
powitanie
.
setText
(
"Cześć "
+
imie
);
powitanie
.
setForeground
(
Color
.
MAGENTA
);
});
okno
.
setVisible
(
true
);
System
.
out
.
println
(
"okno wyświetlone, koniec main"
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment