Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
2
20231104-KursPodstawowyALX
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
20231104-KursPodstawowyALX
Commits
b1b0df29
Commit
b1b0df29
authored
Jan 07, 2024
by
Patryk Czarnik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
obsługa zdarzeń - początek
parent
fda66b83
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
171 additions
and
0 deletions
+171
-0
MojListener.java
src/main/java/p30_swing/zdarzenia/MojListener.java
+13
-0
Rozmowa0.java
src/main/java/p30_swing/zdarzenia/Rozmowa0.java
+74
-0
Rozmowa1.java
src/main/java/p30_swing/zdarzenia/Rozmowa1.java
+84
-0
No files found.
src/main/java/p30_swing/zdarzenia/MojListener.java
0 → 100644
View file @
b1b0df29
package
p30_swing
.
zdarzenia
;
import
java.awt.event.ActionEvent
;
import
java.awt.event.ActionListener
;
public
class
MojListener
implements
ActionListener
{
@Override
public
void
actionPerformed
(
ActionEvent
evt
)
{
System
.
out
.
println
(
"kliknięto guzik"
);
}
}
src/main/java/p30_swing/zdarzenia/Rozmowa0.java
0 → 100644
View file @
b1b0df29
package
p30_swing
.
zdarzenia
;
import
java.awt.Color
;
import
java.awt.Dimension
;
import
java.awt.Font
;
import
java.awt.LayoutManager
;
import
javax.swing.BorderFactory
;
import
javax.swing.Box
;
import
javax.swing.BoxLayout
;
import
javax.swing.JButton
;
import
javax.swing.JFrame
;
import
javax.swing.JLabel
;
import
javax.swing.JPanel
;
import
javax.swing.JTextField
;
public
class
Rozmowa0
{
private
static
final
Font
FONT
=
new
Font
(
"Arial"
,
Font
.
BOLD
,
32
);
private
static
final
Dimension
odstep
=
new
Dimension
(
0
,
10
);
public
static
void
main
(
String
[]
args
)
{
JFrame
okno
=
new
JFrame
(
"Rozmowa"
);
okno
.
setDefaultCloseOperation
(
JFrame
.
EXIT_ON_CLOSE
);
JPanel
panel
=
new
JPanel
();
okno
.
setContentPane
(
panel
);
// panel jest wnętrzem okna
// panel.setBorder(BorderFactory.createLineBorder(Color.BLUE, 5));
panel
.
setBorder
(
BorderFactory
.
createEmptyBorder
(
5
,
10
,
5
,
10
));
LayoutManager
layout
=
new
BoxLayout
(
panel
,
BoxLayout
.
Y_AXIS
);
panel
.
setLayout
(
layout
);
JLabel
pytanie
=
new
JLabel
(
"Jak masz na imię?"
);
pytanie
.
setFont
(
FONT
);
panel
.
add
(
pytanie
);
panel
.
add
(
Box
.
createRigidArea
(
odstep
));
JTextField
pole
=
new
JTextField
();
pole
.
setFont
(
FONT
);
pole
.
setForeground
(
Color
.
MAGENTA
);
panel
.
add
(
pole
);
panel
.
add
(
Box
.
createRigidArea
(
odstep
));
JButton
guzik
=
new
JButton
(
"OK"
);
guzik
.
setFont
(
FONT
);
guzik
.
setMaximumSize
(
new
Dimension
(
Integer
.
MAX_VALUE
,
30
));
panel
.
add
(
guzik
);
panel
.
add
(
Box
.
createRigidArea
(
odstep
));
JLabel
powitanie
=
new
JLabel
(
"Witaj"
);
powitanie
.
setFont
(
FONT
);
powitanie
.
setForeground
(
Color
.
BLUE
);
panel
.
add
(
powitanie
);
panel
.
add
(
Box
.
createRigidArea
(
odstep
));
JButton
guzik2
=
new
JButton
(
"Niespodzianka"
);
guzik2
.
setFont
(
FONT
);
guzik2
.
setForeground
(
Color
.
RED
);
guzik2
.
setMaximumSize
(
new
Dimension
(
Integer
.
MAX_VALUE
,
30
));
panel
.
add
(
guzik2
);
panel
.
add
(
Box
.
createRigidArea
(
odstep
));
okno
.
pack
();
okno
.
setVisible
(
true
);
System
.
out
.
println
(
"okno wyświetlone, koniec main"
);
}
}
src/main/java/p30_swing/zdarzenia/Rozmowa1.java
0 → 100644
View file @
b1b0df29
package
p30_swing
.
zdarzenia
;
import
java.awt.Color
;
import
java.awt.Dimension
;
import
java.awt.Font
;
import
java.awt.LayoutManager
;
import
javax.swing.BorderFactory
;
import
javax.swing.Box
;
import
javax.swing.BoxLayout
;
import
javax.swing.JButton
;
import
javax.swing.JFrame
;
import
javax.swing.JLabel
;
import
javax.swing.JOptionPane
;
import
javax.swing.JPanel
;
import
javax.swing.JTextField
;
public
class
Rozmowa1
{
private
static
final
Font
FONT
=
new
Font
(
"Arial"
,
Font
.
BOLD
,
32
);
private
static
final
Dimension
odstep
=
new
Dimension
(
0
,
10
);
public
static
void
main
(
String
[]
args
)
{
JFrame
okno
=
new
JFrame
(
"Rozmowa"
);
okno
.
setDefaultCloseOperation
(
JFrame
.
EXIT_ON_CLOSE
);
JPanel
panel
=
new
JPanel
();
okno
.
setContentPane
(
panel
);
// panel jest wnętrzem okna
// panel.setBorder(BorderFactory.createLineBorder(Color.BLUE, 5));
panel
.
setBorder
(
BorderFactory
.
createEmptyBorder
(
5
,
10
,
5
,
10
));
LayoutManager
layout
=
new
BoxLayout
(
panel
,
BoxLayout
.
Y_AXIS
);
panel
.
setLayout
(
layout
);
JLabel
pytanie
=
new
JLabel
(
"Jak masz na imię?"
);
pytanie
.
setFont
(
FONT
);
panel
.
add
(
pytanie
);
panel
.
add
(
Box
.
createRigidArea
(
odstep
));
JTextField
pole
=
new
JTextField
();
pole
.
setFont
(
FONT
);
pole
.
setForeground
(
Color
.
MAGENTA
);
panel
.
add
(
pole
);
panel
.
add
(
Box
.
createRigidArea
(
odstep
));
JButton
guzik
=
new
JButton
(
"OK"
);
guzik
.
setFont
(
FONT
);
guzik
.
setMaximumSize
(
new
Dimension
(
Integer
.
MAX_VALUE
,
30
));
panel
.
add
(
guzik
);
panel
.
add
(
Box
.
createRigidArea
(
odstep
));
JLabel
powitanie
=
new
JLabel
(
"Witaj"
);
powitanie
.
setFont
(
FONT
);
powitanie
.
setForeground
(
Color
.
BLUE
);
panel
.
add
(
powitanie
);
panel
.
add
(
Box
.
createRigidArea
(
odstep
));
JButton
guzik2
=
new
JButton
(
"Niespodzianka"
);
guzik2
.
setFont
(
FONT
);
guzik2
.
setForeground
(
Color
.
RED
);
guzik2
.
setMaximumSize
(
new
Dimension
(
Integer
.
MAX_VALUE
,
30
));
panel
.
add
(
guzik2
);
panel
.
add
(
Box
.
createRigidArea
(
odstep
));
okno
.
pack
();
MojListener
listener
=
new
MojListener
();
guzik
.
addActionListener
(
listener
);
// listenery można też tworzyć jako klasy anonimowe lub (od Javy 8) jako wyrażenia lambda
guzik2
.
addActionListener
(
evt
->
{
JOptionPane
.
showMessageDialog
(
okno
,
"Kliknięto drugi guzik"
);
});
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