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
c6f21c80
Commit
c6f21c80
authored
Jan 07, 2024
by
Patryk Czarnik
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dodatkowe przykłady swing
parent
49aff2e7
Hide whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
1397 additions
and
0 deletions
+1397
-0
LogikaKalkulatora.java
src/main/java/kalkulator/LogikaKalkulatora.java
+15
-0
OknoKalkulatora.java
src/main/java/kalkulator/OknoKalkulatora.java
+137
-0
OknoKalkulatora0.java
src/main/java/kalkulator/OknoKalkulatora0.java
+138
-0
OknoKalkulatora1.java
src/main/java/kalkulator/OknoKalkulatora1.java
+151
-0
OknoKalkulatora2.java
src/main/java/kalkulator/OknoKalkulatora2.java
+153
-0
OknoKalkulatora3.java
src/main/java/kalkulator/OknoKalkulatora3.java
+194
-0
OknoKalkulatora4.java
src/main/java/kalkulator/OknoKalkulatora4.java
+200
-0
Layout_Border.java
src/main/java/p30_swing/layout/Layout_Border.java
+36
-0
Layout_Box.java
src/main/java/p30_swing/layout/Layout_Box.java
+36
-0
Layout_BoxY.java
src/main/java/p30_swing/layout/Layout_BoxY.java
+35
-0
Layout_Flow.java
src/main/java/p30_swing/layout/Layout_Flow.java
+48
-0
Layout_Flow2.java
src/main/java/p30_swing/layout/Layout_Flow2.java
+48
-0
Layout_Grid.java
src/main/java/p30_swing/layout/Layout_Grid.java
+51
-0
WypiszDostepneStyle.java
src/main/java/p30_swing/layout/WypiszDostepneStyle.java
+10
-0
Rozmowa_Obiektowo.java
src/main/java/p30_swing/zdarzenia/Rozmowa_Obiektowo.java
+145
-0
No files found.
src/main/java/kalkulator/LogikaKalkulatora.java
0 → 100644
View file @
c6f21c80
package
kalkulator
;
public
class
LogikaKalkulatora
{
public
static
long
oblicz
(
long
arg1
,
long
arg2
,
String
operacja
)
{
switch
(
operacja
)
{
case
"+"
:
return
arg1
+
arg2
;
case
"-"
:
return
arg1
-
arg2
;
case
"*"
:
return
arg1
*
arg2
;
case
"/"
:
return
arg1
/
arg2
;
default
:
return
0
;
}
}
}
src/main/java/kalkulator/OknoKalkulatora.java
0 → 100644
View file @
c6f21c80
package
kalkulator
;
/**
*
* @author patryk
*/
public
class
OknoKalkulatora
extends
javax
.
swing
.
JFrame
{
/**
* Creates new form OknoKalkulatora
*/
public
OknoKalkulatora
()
{
initComponents
();
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings
(
"unchecked"
)
// <editor-fold defaultstate="collapsed" desc="Generated Code">
private
void
initComponents
()
{
jTextField1
=
new
javax
.
swing
.
JTextField
();
jTextField2
=
new
javax
.
swing
.
JTextField
();
jComboBox1
=
new
javax
.
swing
.
JComboBox
<>();
jButton1
=
new
javax
.
swing
.
JButton
();
jTextField3
=
new
javax
.
swing
.
JTextField
();
setDefaultCloseOperation
(
javax
.
swing
.
WindowConstants
.
EXIT_ON_CLOSE
);
setTitle
(
"Kalkulator Java"
);
jTextField1
.
setFont
(
new
java
.
awt
.
Font
(
"Dialog"
,
1
,
24
));
// NOI18N
jTextField2
.
setFont
(
new
java
.
awt
.
Font
(
"Dialog"
,
1
,
24
));
// NOI18N
jComboBox1
.
setFont
(
new
java
.
awt
.
Font
(
"Dialog"
,
1
,
24
));
// NOI18N
jComboBox1
.
setModel
(
new
javax
.
swing
.
DefaultComboBoxModel
<>(
new
String
[]
{
"+"
,
"-"
,
"*"
,
"/"
}));
jButton1
.
setFont
(
new
java
.
awt
.
Font
(
"Dialog"
,
1
,
24
));
// NOI18N
jButton1
.
setText
(
"Oblicz"
);
jButton1
.
addActionListener
(
new
java
.
awt
.
event
.
ActionListener
()
{
public
void
actionPerformed
(
java
.
awt
.
event
.
ActionEvent
evt
)
{
jButton1ActionPerformed
(
evt
);
}
});
jTextField3
.
setFont
(
new
java
.
awt
.
Font
(
"Dialog"
,
1
,
24
));
// NOI18N
jTextField3
.
setText
(
"0"
);
javax
.
swing
.
GroupLayout
layout
=
new
javax
.
swing
.
GroupLayout
(
getContentPane
());
getContentPane
().
setLayout
(
layout
);
layout
.
setHorizontalGroup
(
layout
.
createParallelGroup
(
javax
.
swing
.
GroupLayout
.
Alignment
.
LEADING
)
.
addGroup
(
layout
.
createSequentialGroup
()
.
addContainerGap
()
.
addGroup
(
layout
.
createParallelGroup
(
javax
.
swing
.
GroupLayout
.
Alignment
.
TRAILING
,
false
)
.
addComponent
(
jButton1
,
javax
.
swing
.
GroupLayout
.
DEFAULT_SIZE
,
403
,
Short
.
MAX_VALUE
)
.
addComponent
(
jTextField1
))
.
addPreferredGap
(
javax
.
swing
.
LayoutStyle
.
ComponentPlacement
.
RELATED
)
.
addGroup
(
layout
.
createParallelGroup
(
javax
.
swing
.
GroupLayout
.
Alignment
.
LEADING
)
.
addGroup
(
layout
.
createSequentialGroup
()
.
addComponent
(
jComboBox1
,
0
,
128
,
Short
.
MAX_VALUE
)
.
addPreferredGap
(
javax
.
swing
.
LayoutStyle
.
ComponentPlacement
.
RELATED
)
.
addComponent
(
jTextField2
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
,
403
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
))
.
addComponent
(
jTextField3
))
.
addContainerGap
())
);
layout
.
setVerticalGroup
(
layout
.
createParallelGroup
(
javax
.
swing
.
GroupLayout
.
Alignment
.
LEADING
)
.
addGroup
(
layout
.
createSequentialGroup
()
.
addContainerGap
()
.
addGroup
(
layout
.
createParallelGroup
(
javax
.
swing
.
GroupLayout
.
Alignment
.
LEADING
,
false
)
.
addComponent
(
jComboBox1
,
javax
.
swing
.
GroupLayout
.
DEFAULT_SIZE
,
64
,
Short
.
MAX_VALUE
)
.
addComponent
(
jTextField2
)
.
addComponent
(
jTextField1
))
.
addGap
(
18
,
18
,
18
)
.
addGroup
(
layout
.
createParallelGroup
(
javax
.
swing
.
GroupLayout
.
Alignment
.
LEADING
,
false
)
.
addComponent
(
jButton1
,
javax
.
swing
.
GroupLayout
.
DEFAULT_SIZE
,
72
,
Short
.
MAX_VALUE
)
.
addComponent
(
jTextField3
))
.
addContainerGap
(
61
,
Short
.
MAX_VALUE
))
);
pack
();
}
// </editor-fold>
private
void
jButton1ActionPerformed
(
java
.
awt
.
event
.
ActionEvent
evt
)
{
long
liczba1
=
Long
.
parseLong
(
jTextField1
.
getText
());
long
liczba2
=
Long
.
parseLong
(
jTextField2
.
getText
());
long
wynik
=
liczba1
+
liczba2
;
jTextField3
.
setText
(
String
.
valueOf
(
wynik
));
}
/**
* @param args the command line arguments
*/
public
static
void
main
(
String
args
[])
{
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try
{
for
(
javax
.
swing
.
UIManager
.
LookAndFeelInfo
info
:
javax
.
swing
.
UIManager
.
getInstalledLookAndFeels
())
{
if
(
"Nimbus"
.
equals
(
info
.
getName
()))
{
javax
.
swing
.
UIManager
.
setLookAndFeel
(
info
.
getClassName
());
break
;
}
}
}
catch
(
ClassNotFoundException
ex
)
{
java
.
util
.
logging
.
Logger
.
getLogger
(
OknoKalkulatora
.
class
.
getName
()).
log
(
java
.
util
.
logging
.
Level
.
SEVERE
,
null
,
ex
);
}
catch
(
InstantiationException
ex
)
{
java
.
util
.
logging
.
Logger
.
getLogger
(
OknoKalkulatora
.
class
.
getName
()).
log
(
java
.
util
.
logging
.
Level
.
SEVERE
,
null
,
ex
);
}
catch
(
IllegalAccessException
ex
)
{
java
.
util
.
logging
.
Logger
.
getLogger
(
OknoKalkulatora
.
class
.
getName
()).
log
(
java
.
util
.
logging
.
Level
.
SEVERE
,
null
,
ex
);
}
catch
(
javax
.
swing
.
UnsupportedLookAndFeelException
ex
)
{
java
.
util
.
logging
.
Logger
.
getLogger
(
OknoKalkulatora
.
class
.
getName
()).
log
(
java
.
util
.
logging
.
Level
.
SEVERE
,
null
,
ex
);
}
//</editor-fold>
/* Create and display the form */
java
.
awt
.
EventQueue
.
invokeLater
(
new
Runnable
()
{
public
void
run
()
{
new
OknoKalkulatora
().
setVisible
(
true
);
}
});
}
// Variables declaration - do not modify
private
javax
.
swing
.
JButton
jButton1
;
private
javax
.
swing
.
JComboBox
<
String
>
jComboBox1
;
private
javax
.
swing
.
JTextField
jTextField1
;
private
javax
.
swing
.
JTextField
jTextField2
;
private
javax
.
swing
.
JTextField
jTextField3
;
// End of variables declaration
}
src/main/java/kalkulator/OknoKalkulatora0.java
0 → 100644
View file @
c6f21c80
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/GUIForms/JFrame.java to edit this template
*/
package
kalkulator
;
/**
*
* @author patryk
*/
public
class
OknoKalkulatora0
extends
javax
.
swing
.
JFrame
{
/**
* Creates new form OknoKalkulatora
*/
public
OknoKalkulatora0
()
{
initComponents
();
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings
(
"unchecked"
)
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private
void
initComponents
()
{
jTextField1
=
new
javax
.
swing
.
JTextField
();
jTextField2
=
new
javax
.
swing
.
JTextField
();
jComboBox1
=
new
javax
.
swing
.
JComboBox
<>();
jButton1
=
new
javax
.
swing
.
JButton
();
jTextField3
=
new
javax
.
swing
.
JTextField
();
setDefaultCloseOperation
(
javax
.
swing
.
WindowConstants
.
EXIT_ON_CLOSE
);
setTitle
(
"Kalkulator"
);
jTextField1
.
setFont
(
new
java
.
awt
.
Font
(
"Dialog"
,
1
,
36
));
// NOI18N
jTextField1
.
setText
(
"0"
);
jTextField2
.
setFont
(
new
java
.
awt
.
Font
(
"Dialog"
,
1
,
36
));
// NOI18N
jTextField2
.
setText
(
"0"
);
jComboBox1
.
setFont
(
new
java
.
awt
.
Font
(
"Dialog"
,
1
,
36
));
// NOI18N
jComboBox1
.
setModel
(
new
javax
.
swing
.
DefaultComboBoxModel
<>(
new
String
[]
{
"+"
,
"-"
,
"*"
,
"/"
}));
jButton1
.
setFont
(
new
java
.
awt
.
Font
(
"Dialog"
,
1
,
36
));
// NOI18N
jButton1
.
setText
(
"Oblicz"
);
jTextField3
.
setFont
(
new
java
.
awt
.
Font
(
"Dialog"
,
1
,
36
));
// NOI18N
jTextField3
.
setText
(
"0"
);
javax
.
swing
.
GroupLayout
layout
=
new
javax
.
swing
.
GroupLayout
(
getContentPane
());
getContentPane
().
setLayout
(
layout
);
layout
.
setHorizontalGroup
(
layout
.
createParallelGroup
(
javax
.
swing
.
GroupLayout
.
Alignment
.
LEADING
)
.
addGroup
(
layout
.
createSequentialGroup
()
.
addContainerGap
()
.
addGroup
(
layout
.
createParallelGroup
(
javax
.
swing
.
GroupLayout
.
Alignment
.
LEADING
)
.
addGroup
(
layout
.
createSequentialGroup
()
.
addComponent
(
jButton1
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
,
415
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
)
.
addGap
(
169
,
169
,
169
)
.
addComponent
(
jTextField3
))
.
addGroup
(
layout
.
createSequentialGroup
()
.
addComponent
(
jTextField1
,
javax
.
swing
.
GroupLayout
.
DEFAULT_SIZE
,
414
,
Short
.
MAX_VALUE
)
.
addGap
(
18
,
18
,
18
)
.
addComponent
(
jComboBox1
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
,
133
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
)
.
addGap
(
18
,
18
,
18
)
.
addComponent
(
jTextField2
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
,
415
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
)))
.
addContainerGap
())
);
layout
.
linkSize
(
javax
.
swing
.
SwingConstants
.
HORIZONTAL
,
new
java
.
awt
.
Component
[]
{
jTextField1
,
jTextField2
});
layout
.
setVerticalGroup
(
layout
.
createParallelGroup
(
javax
.
swing
.
GroupLayout
.
Alignment
.
LEADING
)
.
addGroup
(
layout
.
createSequentialGroup
()
.
addContainerGap
()
.
addGroup
(
layout
.
createParallelGroup
(
javax
.
swing
.
GroupLayout
.
Alignment
.
BASELINE
)
.
addComponent
(
jTextField1
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
,
60
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
)
.
addComponent
(
jTextField2
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
,
javax
.
swing
.
GroupLayout
.
DEFAULT_SIZE
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
)
.
addComponent
(
jComboBox1
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
,
javax
.
swing
.
GroupLayout
.
DEFAULT_SIZE
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
))
.
addGap
(
18
,
18
,
18
)
.
addGroup
(
layout
.
createParallelGroup
(
javax
.
swing
.
GroupLayout
.
Alignment
.
BASELINE
)
.
addComponent
(
jButton1
)
.
addComponent
(
jTextField3
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
,
javax
.
swing
.
GroupLayout
.
DEFAULT_SIZE
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
))
.
addContainerGap
(
20
,
Short
.
MAX_VALUE
))
);
layout
.
linkSize
(
javax
.
swing
.
SwingConstants
.
VERTICAL
,
new
java
.
awt
.
Component
[]
{
jButton1
,
jComboBox1
,
jTextField1
,
jTextField2
,
jTextField3
});
pack
();
}
// </editor-fold>//GEN-END:initComponents
/**
* @param args the command line arguments
*/
public
static
void
main
(
String
args
[])
{
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try
{
for
(
javax
.
swing
.
UIManager
.
LookAndFeelInfo
info
:
javax
.
swing
.
UIManager
.
getInstalledLookAndFeels
())
{
if
(
"Nimbus"
.
equals
(
info
.
getName
()))
{
javax
.
swing
.
UIManager
.
setLookAndFeel
(
info
.
getClassName
());
break
;
}
}
}
catch
(
ClassNotFoundException
ex
)
{
java
.
util
.
logging
.
Logger
.
getLogger
(
OknoKalkulatora0
.
class
.
getName
()).
log
(
java
.
util
.
logging
.
Level
.
SEVERE
,
null
,
ex
);
}
catch
(
InstantiationException
ex
)
{
java
.
util
.
logging
.
Logger
.
getLogger
(
OknoKalkulatora0
.
class
.
getName
()).
log
(
java
.
util
.
logging
.
Level
.
SEVERE
,
null
,
ex
);
}
catch
(
IllegalAccessException
ex
)
{
java
.
util
.
logging
.
Logger
.
getLogger
(
OknoKalkulatora0
.
class
.
getName
()).
log
(
java
.
util
.
logging
.
Level
.
SEVERE
,
null
,
ex
);
}
catch
(
javax
.
swing
.
UnsupportedLookAndFeelException
ex
)
{
java
.
util
.
logging
.
Logger
.
getLogger
(
OknoKalkulatora0
.
class
.
getName
()).
log
(
java
.
util
.
logging
.
Level
.
SEVERE
,
null
,
ex
);
}
//</editor-fold>
//</editor-fold>
/* Create and display the form */
java
.
awt
.
EventQueue
.
invokeLater
(
new
Runnable
()
{
public
void
run
()
{
new
OknoKalkulatora0
().
setVisible
(
true
);
}
});
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private
javax
.
swing
.
JButton
jButton1
;
private
javax
.
swing
.
JComboBox
<
String
>
jComboBox1
;
private
javax
.
swing
.
JTextField
jTextField1
;
private
javax
.
swing
.
JTextField
jTextField2
;
private
javax
.
swing
.
JTextField
jTextField3
;
// End of variables declaration//GEN-END:variables
}
src/main/java/kalkulator/OknoKalkulatora1.java
0 → 100644
View file @
c6f21c80
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/GUIForms/JFrame.java to edit this template
*/
package
kalkulator
;
/**
*
* @author patryk
*/
public
class
OknoKalkulatora1
extends
javax
.
swing
.
JFrame
{
/**
* Creates new form OknoKalkulatora
*/
public
OknoKalkulatora1
()
{
initComponents
();
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings
(
"unchecked"
)
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private
void
initComponents
()
{
jTextField1
=
new
javax
.
swing
.
JTextField
();
jTextField2
=
new
javax
.
swing
.
JTextField
();
jComboBox1
=
new
javax
.
swing
.
JComboBox
<>();
jButton1
=
new
javax
.
swing
.
JButton
();
jTextField3
=
new
javax
.
swing
.
JTextField
();
setDefaultCloseOperation
(
javax
.
swing
.
WindowConstants
.
EXIT_ON_CLOSE
);
setTitle
(
"Kalkulator"
);
jTextField1
.
setFont
(
new
java
.
awt
.
Font
(
"Dialog"
,
1
,
36
));
// NOI18N
jTextField1
.
setHorizontalAlignment
(
javax
.
swing
.
JTextField
.
RIGHT
);
jTextField2
.
setFont
(
new
java
.
awt
.
Font
(
"Dialog"
,
1
,
36
));
// NOI18N
jTextField2
.
setHorizontalAlignment
(
javax
.
swing
.
JTextField
.
RIGHT
);
jComboBox1
.
setFont
(
new
java
.
awt
.
Font
(
"Dialog"
,
1
,
36
));
// NOI18N
jComboBox1
.
setModel
(
new
javax
.
swing
.
DefaultComboBoxModel
<>(
new
String
[]
{
"+"
,
"-"
,
"*"
,
"/"
}));
jButton1
.
setFont
(
new
java
.
awt
.
Font
(
"Dialog"
,
1
,
36
));
// NOI18N
jButton1
.
setText
(
"Oblicz"
);
jButton1
.
addActionListener
(
new
java
.
awt
.
event
.
ActionListener
()
{
public
void
actionPerformed
(
java
.
awt
.
event
.
ActionEvent
evt
)
{
jButton1ActionPerformed
(
evt
);
}
});
jTextField3
.
setFont
(
new
java
.
awt
.
Font
(
"Dialog"
,
1
,
36
));
// NOI18N
jTextField3
.
setHorizontalAlignment
(
javax
.
swing
.
JTextField
.
RIGHT
);
jTextField3
.
setText
(
"0"
);
javax
.
swing
.
GroupLayout
layout
=
new
javax
.
swing
.
GroupLayout
(
getContentPane
());
getContentPane
().
setLayout
(
layout
);
layout
.
setHorizontalGroup
(
layout
.
createParallelGroup
(
javax
.
swing
.
GroupLayout
.
Alignment
.
LEADING
)
.
addGroup
(
layout
.
createSequentialGroup
()
.
addContainerGap
()
.
addGroup
(
layout
.
createParallelGroup
(
javax
.
swing
.
GroupLayout
.
Alignment
.
LEADING
)
.
addGroup
(
layout
.
createSequentialGroup
()
.
addComponent
(
jButton1
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
,
415
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
)
.
addGap
(
169
,
169
,
169
)
.
addComponent
(
jTextField3
))
.
addGroup
(
layout
.
createSequentialGroup
()
.
addComponent
(
jTextField1
,
javax
.
swing
.
GroupLayout
.
DEFAULT_SIZE
,
414
,
Short
.
MAX_VALUE
)
.
addGap
(
18
,
18
,
18
)
.
addComponent
(
jComboBox1
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
,
133
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
)
.
addGap
(
18
,
18
,
18
)
.
addComponent
(
jTextField2
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
,
415
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
)))
.
addContainerGap
())
);
layout
.
linkSize
(
javax
.
swing
.
SwingConstants
.
HORIZONTAL
,
new
java
.
awt
.
Component
[]
{
jTextField1
,
jTextField2
});
layout
.
setVerticalGroup
(
layout
.
createParallelGroup
(
javax
.
swing
.
GroupLayout
.
Alignment
.
LEADING
)
.
addGroup
(
layout
.
createSequentialGroup
()
.
addContainerGap
()
.
addGroup
(
layout
.
createParallelGroup
(
javax
.
swing
.
GroupLayout
.
Alignment
.
BASELINE
)
.
addComponent
(
jTextField1
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
,
60
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
)
.
addComponent
(
jTextField2
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
,
javax
.
swing
.
GroupLayout
.
DEFAULT_SIZE
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
)
.
addComponent
(
jComboBox1
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
,
javax
.
swing
.
GroupLayout
.
DEFAULT_SIZE
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
))
.
addGap
(
18
,
18
,
18
)
.
addGroup
(
layout
.
createParallelGroup
(
javax
.
swing
.
GroupLayout
.
Alignment
.
BASELINE
)
.
addComponent
(
jButton1
)
.
addComponent
(
jTextField3
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
,
javax
.
swing
.
GroupLayout
.
DEFAULT_SIZE
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
))
.
addContainerGap
(
20
,
Short
.
MAX_VALUE
))
);
layout
.
linkSize
(
javax
.
swing
.
SwingConstants
.
VERTICAL
,
new
java
.
awt
.
Component
[]
{
jButton1
,
jComboBox1
,
jTextField1
,
jTextField2
,
jTextField3
});
pack
();
}
// </editor-fold>//GEN-END:initComponents
private
void
jButton1ActionPerformed
(
java
.
awt
.
event
.
ActionEvent
evt
)
{
//GEN-FIRST:event_jButton1ActionPerformed
long
liczba1
=
Long
.
parseLong
(
jTextField1
.
getText
());
long
liczba2
=
Long
.
parseLong
(
jTextField2
.
getText
());
long
wynik
=
liczba1
+
liczba2
;
jTextField3
.
setText
(
String
.
valueOf
(
wynik
));
}
//GEN-LAST:event_jButton1ActionPerformed
/**
* @param args the command line arguments
*/
public
static
void
main
(
String
args
[])
{
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try
{
for
(
javax
.
swing
.
UIManager
.
LookAndFeelInfo
info
:
javax
.
swing
.
UIManager
.
getInstalledLookAndFeels
())
{
if
(
"Nimbus"
.
equals
(
info
.
getName
()))
{
javax
.
swing
.
UIManager
.
setLookAndFeel
(
info
.
getClassName
());
break
;
}
}
}
catch
(
ClassNotFoundException
ex
)
{
java
.
util
.
logging
.
Logger
.
getLogger
(
OknoKalkulatora1
.
class
.
getName
()).
log
(
java
.
util
.
logging
.
Level
.
SEVERE
,
null
,
ex
);
}
catch
(
InstantiationException
ex
)
{
java
.
util
.
logging
.
Logger
.
getLogger
(
OknoKalkulatora1
.
class
.
getName
()).
log
(
java
.
util
.
logging
.
Level
.
SEVERE
,
null
,
ex
);
}
catch
(
IllegalAccessException
ex
)
{
java
.
util
.
logging
.
Logger
.
getLogger
(
OknoKalkulatora1
.
class
.
getName
()).
log
(
java
.
util
.
logging
.
Level
.
SEVERE
,
null
,
ex
);
}
catch
(
javax
.
swing
.
UnsupportedLookAndFeelException
ex
)
{
java
.
util
.
logging
.
Logger
.
getLogger
(
OknoKalkulatora1
.
class
.
getName
()).
log
(
java
.
util
.
logging
.
Level
.
SEVERE
,
null
,
ex
);
}
//</editor-fold>
//</editor-fold>
/* Create and display the form */
java
.
awt
.
EventQueue
.
invokeLater
(
new
Runnable
()
{
public
void
run
()
{
new
OknoKalkulatora1
().
setVisible
(
true
);
}
});
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private
javax
.
swing
.
JButton
jButton1
;
private
javax
.
swing
.
JComboBox
<
String
>
jComboBox1
;
private
javax
.
swing
.
JTextField
jTextField1
;
private
javax
.
swing
.
JTextField
jTextField2
;
private
javax
.
swing
.
JTextField
jTextField3
;
// End of variables declaration//GEN-END:variables
}
src/main/java/kalkulator/OknoKalkulatora2.java
0 → 100644
View file @
c6f21c80
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/GUIForms/JFrame.java to edit this template
*/
package
kalkulator
;
/**
*
* @author patryk
*/
public
class
OknoKalkulatora2
extends
javax
.
swing
.
JFrame
{
/**
* Creates new form OknoKalkulatora
*/
public
OknoKalkulatora2
()
{
initComponents
();
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings
(
"unchecked"
)
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private
void
initComponents
()
{
jTextField1
=
new
javax
.
swing
.
JTextField
();
jTextField2
=
new
javax
.
swing
.
JTextField
();
jComboBox1
=
new
javax
.
swing
.
JComboBox
<>();
jButton1
=
new
javax
.
swing
.
JButton
();
jTextField3
=
new
javax
.
swing
.
JTextField
();
setDefaultCloseOperation
(
javax
.
swing
.
WindowConstants
.
EXIT_ON_CLOSE
);
setTitle
(
"Kalkulator"
);
jTextField1
.
setFont
(
new
java
.
awt
.
Font
(
"Dialog"
,
1
,
36
));
// NOI18N
jTextField1
.
setHorizontalAlignment
(
javax
.
swing
.
JTextField
.
RIGHT
);
jTextField2
.
setFont
(
new
java
.
awt
.
Font
(
"Dialog"
,
1
,
36
));
// NOI18N
jTextField2
.
setHorizontalAlignment
(
javax
.
swing
.
JTextField
.
RIGHT
);
jComboBox1
.
setFont
(
new
java
.
awt
.
Font
(
"Dialog"
,
1
,
36
));
// NOI18N
jComboBox1
.
setModel
(
new
javax
.
swing
.
DefaultComboBoxModel
<>(
new
String
[]
{
"+"
,
"-"
,
"*"
,
"/"
}));
jButton1
.
setFont
(
new
java
.
awt
.
Font
(
"Dialog"
,
1
,
36
));
// NOI18N
jButton1
.
setText
(
"Oblicz"
);
jButton1
.
addActionListener
(
new
java
.
awt
.
event
.
ActionListener
()
{
public
void
actionPerformed
(
java
.
awt
.
event
.
ActionEvent
evt
)
{
jButton1ActionPerformed
(
evt
);
}
});
jTextField3
.
setFont
(
new
java
.
awt
.
Font
(
"Dialog"
,
1
,
36
));
// NOI18N
jTextField3
.
setHorizontalAlignment
(
javax
.
swing
.
JTextField
.
RIGHT
);
jTextField3
.
setText
(
"0"
);
javax
.
swing
.
GroupLayout
layout
=
new
javax
.
swing
.
GroupLayout
(
getContentPane
());
getContentPane
().
setLayout
(
layout
);
layout
.
setHorizontalGroup
(
layout
.
createParallelGroup
(
javax
.
swing
.
GroupLayout
.
Alignment
.
LEADING
)
.
addGroup
(
layout
.
createSequentialGroup
()
.
addContainerGap
()
.
addGroup
(
layout
.
createParallelGroup
(
javax
.
swing
.
GroupLayout
.
Alignment
.
LEADING
)
.
addGroup
(
layout
.
createSequentialGroup
()
.
addComponent
(
jButton1
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
,
415
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
)
.
addGap
(
169
,
169
,
169
)
.
addComponent
(
jTextField3
))
.
addGroup
(
layout
.
createSequentialGroup
()
.
addComponent
(
jTextField1
,
javax
.
swing
.
GroupLayout
.
DEFAULT_SIZE
,
414
,
Short
.
MAX_VALUE
)
.
addGap
(
18
,
18
,
18
)
.
addComponent
(
jComboBox1
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
,
133
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
)
.
addGap
(
18
,
18
,
18
)
.
addComponent
(
jTextField2
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
,
415
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
)))
.
addContainerGap
())
);
layout
.
linkSize
(
javax
.
swing
.
SwingConstants
.
HORIZONTAL
,
new
java
.
awt
.
Component
[]
{
jTextField1
,
jTextField2
});
layout
.
setVerticalGroup
(
layout
.
createParallelGroup
(
javax
.
swing
.
GroupLayout
.
Alignment
.
LEADING
)
.
addGroup
(
layout
.
createSequentialGroup
()
.
addContainerGap
()
.
addGroup
(
layout
.
createParallelGroup
(
javax
.
swing
.
GroupLayout
.
Alignment
.
BASELINE
)
.
addComponent
(
jTextField1
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
,
60
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
)
.
addComponent
(
jTextField2
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
,
javax
.
swing
.
GroupLayout
.
DEFAULT_SIZE
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
)
.
addComponent
(
jComboBox1
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
,
javax
.
swing
.
GroupLayout
.
DEFAULT_SIZE
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
))
.
addGap
(
18
,
18
,
18
)
.
addGroup
(
layout
.
createParallelGroup
(
javax
.
swing
.
GroupLayout
.
Alignment
.
BASELINE
)
.
addComponent
(
jButton1
)
.
addComponent
(
jTextField3
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
,
javax
.
swing
.
GroupLayout
.
DEFAULT_SIZE
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
))
.
addContainerGap
(
20
,
Short
.
MAX_VALUE
))
);
layout
.
linkSize
(
javax
.
swing
.
SwingConstants
.
VERTICAL
,
new
java
.
awt
.
Component
[]
{
jButton1
,
jComboBox1
,
jTextField1
,
jTextField2
,
jTextField3
});
pack
();
}
// </editor-fold>//GEN-END:initComponents
private
void
jButton1ActionPerformed
(
java
.
awt
.
event
.
ActionEvent
evt
)
{
//GEN-FIRST:event_jButton1ActionPerformed
long
liczba1
=
Long
.
parseLong
(
jTextField1
.
getText
());
long
liczba2
=
Long
.
parseLong
(
jTextField2
.
getText
());
// String operacja = jComboBox1.getItemAt(jComboBox1.getSelectedIndex());
String
operacja
=
(
String
)
jComboBox1
.
getSelectedItem
();
long
wynik
=
LogikaKalkulatora
.
oblicz
(
liczba1
,
liczba2
,
operacja
);
jTextField3
.
setText
(
String
.
valueOf
(
wynik
));
}
//GEN-LAST:event_jButton1ActionPerformed
/**
* @param args the command line arguments
*/
public
static
void
main
(
String
args
[])
{
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try
{
for
(
javax
.
swing
.
UIManager
.
LookAndFeelInfo
info
:
javax
.
swing
.
UIManager
.
getInstalledLookAndFeels
())
{
if
(
"Nimbus"
.
equals
(
info
.
getName
()))
{
javax
.
swing
.
UIManager
.
setLookAndFeel
(
info
.
getClassName
());
break
;
}
}
}
catch
(
ClassNotFoundException
ex
)
{
java
.
util
.
logging
.
Logger
.
getLogger
(
OknoKalkulatora2
.
class
.
getName
()).
log
(
java
.
util
.
logging
.
Level
.
SEVERE
,
null
,
ex
);
}
catch
(
InstantiationException
ex
)
{
java
.
util
.
logging
.
Logger
.
getLogger
(
OknoKalkulatora2
.
class
.
getName
()).
log
(
java
.
util
.
logging
.
Level
.
SEVERE
,
null
,
ex
);
}
catch
(
IllegalAccessException
ex
)
{
java
.
util
.
logging
.
Logger
.
getLogger
(
OknoKalkulatora2
.
class
.
getName
()).
log
(
java
.
util
.
logging
.
Level
.
SEVERE
,
null
,
ex
);
}
catch
(
javax
.
swing
.
UnsupportedLookAndFeelException
ex
)
{
java
.
util
.
logging
.
Logger
.
getLogger
(
OknoKalkulatora2
.
class
.
getName
()).
log
(
java
.
util
.
logging
.
Level
.
SEVERE
,
null
,
ex
);
}
//</editor-fold>
//</editor-fold>
/* Create and display the form */
java
.
awt
.
EventQueue
.
invokeLater
(
new
Runnable
()
{
public
void
run
()
{
new
OknoKalkulatora2
().
setVisible
(
true
);
}
});
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private
javax
.
swing
.
JButton
jButton1
;
private
javax
.
swing
.
JComboBox
<
String
>
jComboBox1
;
private
javax
.
swing
.
JTextField
jTextField1
;
private
javax
.
swing
.
JTextField
jTextField2
;
private
javax
.
swing
.
JTextField
jTextField3
;
// End of variables declaration//GEN-END:variables
}
src/main/java/kalkulator/OknoKalkulatora3.java
0 → 100644
View file @
c6f21c80
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/GUIForms/JFrame.java to edit this template
*/
package
kalkulator
;
import
java.awt.Color
;
/**
*
* @author patryk
*/
public
class
OknoKalkulatora3
extends
javax
.
swing
.
JFrame
{
/**
* Creates new form OknoKalkulatora
*/
public
OknoKalkulatora3
()
{
initComponents
();
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings
(
"unchecked"
)
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private
void
initComponents
()
{
jTextField1
=
new
javax
.
swing
.
JTextField
();
jTextField2
=
new
javax
.
swing
.
JTextField
();
jComboBox1
=
new
javax
.
swing
.
JComboBox
<>();
jButton1
=
new
javax
.
swing
.
JButton
();
jTextField3
=
new
javax
.
swing
.
JTextField
();
setDefaultCloseOperation
(
javax
.
swing
.
WindowConstants
.
EXIT_ON_CLOSE
);
setTitle
(
"Kalkulator"
);
setResizable
(
false
);
jTextField1
.
setFont
(
new
java
.
awt
.
Font
(
"Dialog"
,
1
,
36
));
// NOI18N
jTextField1
.
setHorizontalAlignment
(
javax
.
swing
.
JTextField
.
RIGHT
);
jTextField1
.
addActionListener
(
new
java
.
awt
.
event
.
ActionListener
()
{
public
void
actionPerformed
(
java
.
awt
.
event
.
ActionEvent
evt
)
{
jTextField1ActionPerformed
(
evt
);
}
});
jTextField2
.
setFont
(
new
java
.
awt
.
Font
(
"Dialog"
,
1
,
36
));
// NOI18N
jTextField2
.
setHorizontalAlignment
(
javax
.
swing
.
JTextField
.
RIGHT
);
jTextField2
.
addActionListener
(
new
java
.
awt
.
event
.
ActionListener
()
{
public
void
actionPerformed
(
java
.
awt
.
event
.
ActionEvent
evt
)
{
jTextField2ActionPerformed
(
evt
);
}
});
jComboBox1
.
setFont
(
new
java
.
awt
.
Font
(
"Dialog"
,
1
,
36
));
// NOI18N
jComboBox1
.
setModel
(
new
javax
.
swing
.
DefaultComboBoxModel
<>(
new
String
[]
{
"+"
,
"-"
,
"*"
,
"/"
}));
jComboBox1
.
addActionListener
(
new
java
.
awt
.
event
.
ActionListener
()
{
public
void
actionPerformed
(
java
.
awt
.
event
.
ActionEvent
evt
)
{
jComboBox1ActionPerformed
(
evt
);
}
});
jButton1
.
setFont
(
new
java
.
awt
.
Font
(
"Dialog"
,
1
,
36
));
// NOI18N
jButton1
.
setText
(
"Oblicz"
);
jButton1
.
addActionListener
(
new
java
.
awt
.
event
.
ActionListener
()
{
public
void
actionPerformed
(
java
.
awt
.
event
.
ActionEvent
evt
)
{
jButton1ActionPerformed
(
evt
);
}
});
jTextField3
.
setEditable
(
false
);
jTextField3
.
setFont
(
new
java
.
awt
.
Font
(
"Dialog"
,
1
,
36
));
// NOI18N
jTextField3
.
setHorizontalAlignment
(
javax
.
swing
.
JTextField
.
RIGHT
);
jTextField3
.
setText
(
"0"
);
javax
.
swing
.
GroupLayout
layout
=
new
javax
.
swing
.
GroupLayout
(
getContentPane
());
getContentPane
().
setLayout
(
layout
);
layout
.
setHorizontalGroup
(
layout
.
createParallelGroup
(
javax
.
swing
.
GroupLayout
.
Alignment
.
LEADING
)
.
addGroup
(
layout
.
createSequentialGroup
()
.
addContainerGap
()
.
addGroup
(
layout
.
createParallelGroup
(
javax
.
swing
.
GroupLayout
.
Alignment
.
LEADING
)
.
addGroup
(
layout
.
createSequentialGroup
()
.
addComponent
(
jButton1
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
,
415
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
)
.
addGap
(
169
,
169
,
169
)
.
addComponent
(
jTextField3
))
.
addGroup
(
layout
.
createSequentialGroup
()
.
addComponent
(
jTextField1
,
javax
.
swing
.
GroupLayout
.
DEFAULT_SIZE
,
414
,
Short
.
MAX_VALUE
)
.
addGap
(
18
,
18
,
18
)
.
addComponent
(
jComboBox1
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
,
133
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
)
.
addGap
(
18
,
18
,
18
)
.
addComponent
(
jTextField2
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
,
415
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
)))
.
addContainerGap
())
);
layout
.
linkSize
(
javax
.
swing
.
SwingConstants
.
HORIZONTAL
,
new
java
.
awt
.
Component
[]
{
jTextField1
,
jTextField2
});
layout
.
setVerticalGroup
(
layout
.
createParallelGroup
(
javax
.
swing
.
GroupLayout
.
Alignment
.
LEADING
)
.
addGroup
(
layout
.
createSequentialGroup
()
.
addContainerGap
()
.
addGroup
(
layout
.
createParallelGroup
(
javax
.
swing
.
GroupLayout
.
Alignment
.
BASELINE
)
.
addComponent
(
jTextField1
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
,
60
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
)
.
addComponent
(
jTextField2
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
,
javax
.
swing
.
GroupLayout
.
DEFAULT_SIZE
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
)
.
addComponent
(
jComboBox1
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
,
javax
.
swing
.
GroupLayout
.
DEFAULT_SIZE
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
))
.
addGap
(
18
,
18
,
18
)
.
addGroup
(
layout
.
createParallelGroup
(
javax
.
swing
.
GroupLayout
.
Alignment
.
BASELINE
)
.
addComponent
(
jButton1
)
.
addComponent
(
jTextField3
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
,
javax
.
swing
.
GroupLayout
.
DEFAULT_SIZE
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
))
.
addContainerGap
(
20
,
Short
.
MAX_VALUE
))
);
layout
.
linkSize
(
javax
.
swing
.
SwingConstants
.
VERTICAL
,
new
java
.
awt
.
Component
[]
{
jButton1
,
jComboBox1
,
jTextField1
,
jTextField2
,
jTextField3
});
pack
();
}
// </editor-fold>//GEN-END:initComponents
private
void
jButton1ActionPerformed
(
java
.
awt
.
event
.
ActionEvent
evt
)
{
//GEN-FIRST:event_jButton1ActionPerformed
przelicz
();
}
//GEN-LAST:event_jButton1ActionPerformed
private
void
jComboBox1ActionPerformed
(
java
.
awt
.
event
.
ActionEvent
evt
)
{
//GEN-FIRST:event_jComboBox1ActionPerformed
przelicz
();
}
//GEN-LAST:event_jComboBox1ActionPerformed
private
void
jTextField1ActionPerformed
(
java
.
awt
.
event
.
ActionEvent
evt
)
{
//GEN-FIRST:event_jTextField1ActionPerformed
przelicz
();
}
//GEN-LAST:event_jTextField1ActionPerformed
private
void
jTextField2ActionPerformed
(
java
.
awt
.
event
.
ActionEvent
evt
)
{
//GEN-FIRST:event_jTextField2ActionPerformed
przelicz
();
}
//GEN-LAST:event_jTextField2ActionPerformed
private
void
przelicz
()
{
try
{
long
liczba1
=
Long
.
parseLong
(
jTextField1
.
getText
());
long
liczba2
=
Long
.
parseLong
(
jTextField2
.
getText
());
// String operacja = jComboBox1.getItemAt(jComboBox1.getSelectedIndex());
String
operacja
=
(
String
)
jComboBox1
.
getSelectedItem
();
long
wynik
=
LogikaKalkulatora
.
oblicz
(
liczba1
,
liczba2
,
operacja
);
jTextField3
.
setText
(
String
.
valueOf
(
wynik
));
jTextField3
.
setForeground
(
Color
.
BLUE
);
}
catch
(
Exception
e
)
{
jTextField3
.
setText
(
"BŁĄD"
);
jTextField3
.
setForeground
(
Color
.
RED
);
}
}
/**
* @param args the command line arguments
*/
public
static
void
main
(
String
args
[])
{
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try
{
for
(
javax
.
swing
.
UIManager
.
LookAndFeelInfo
info
:
javax
.
swing
.
UIManager
.
getInstalledLookAndFeels
())
{
if
(
"Nimbus"
.
equals
(
info
.
getName
()))
{
javax
.
swing
.
UIManager
.
setLookAndFeel
(
info
.
getClassName
());
break
;
}
}
}
catch
(
ClassNotFoundException
ex
)
{
java
.
util
.
logging
.
Logger
.
getLogger
(
OknoKalkulatora3
.
class
.
getName
()).
log
(
java
.
util
.
logging
.
Level
.
SEVERE
,
null
,
ex
);
}
catch
(
InstantiationException
ex
)
{
java
.
util
.
logging
.
Logger
.
getLogger
(
OknoKalkulatora3
.
class
.
getName
()).
log
(
java
.
util
.
logging
.
Level
.
SEVERE
,
null
,
ex
);
}
catch
(
IllegalAccessException
ex
)
{
java
.
util
.
logging
.
Logger
.
getLogger
(
OknoKalkulatora3
.
class
.
getName
()).
log
(
java
.
util
.
logging
.
Level
.
SEVERE
,
null
,
ex
);
}
catch
(
javax
.
swing
.
UnsupportedLookAndFeelException
ex
)
{
java
.
util
.
logging
.
Logger
.
getLogger
(
OknoKalkulatora3
.
class
.
getName
()).
log
(
java
.
util
.
logging
.
Level
.
SEVERE
,
null
,
ex
);
}
//</editor-fold>
//</editor-fold>
/* Create and display the form */
java
.
awt
.
EventQueue
.
invokeLater
(
new
Runnable
()
{
public
void
run
()
{
new
OknoKalkulatora3
().
setVisible
(
true
);
}
});
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private
javax
.
swing
.
JButton
jButton1
;
private
javax
.
swing
.
JComboBox
<
String
>
jComboBox1
;
private
javax
.
swing
.
JTextField
jTextField1
;
private
javax
.
swing
.
JTextField
jTextField2
;
private
javax
.
swing
.
JTextField
jTextField3
;
// End of variables declaration//GEN-END:variables
}
src/main/java/kalkulator/OknoKalkulatora4.java
0 → 100644
View file @
c6f21c80
/*
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
* Click nbfs://nbhost/SystemFileSystem/Templates/GUIForms/JFrame.java to edit this template
*/
package
kalkulator
;
import
java.awt.Color
;
import
javax.swing.event.DocumentEvent
;
import
javax.swing.event.DocumentListener
;
/**
*
* @author patryk
*/
public
class
OknoKalkulatora4
extends
javax
.
swing
.
JFrame
{
/**
* Creates new form OknoKalkulatora
*/
public
OknoKalkulatora4
()
{
initComponents
();
mojeDodatki
();
}
private
void
mojeDodatki
()
{
DocumentListener
dl
=
new
DocumentListener
()
{
public
void
insertUpdate
(
DocumentEvent
evt
)
{
przelicz
();
}
public
void
removeUpdate
(
DocumentEvent
evt
)
{
przelicz
();
}
public
void
changedUpdate
(
DocumentEvent
evt
)
{
przelicz
();
}
};
jTextField1
.
getDocument
().
addDocumentListener
(
dl
);
jTextField2
.
getDocument
().
addDocumentListener
(
dl
);
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
@SuppressWarnings
(
"unchecked"
)
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private
void
initComponents
()
{
jTextField1
=
new
javax
.
swing
.
JTextField
();
jTextField2
=
new
javax
.
swing
.
JTextField
();
jComboBox1
=
new
javax
.
swing
.
JComboBox
<>();
jButton1
=
new
javax
.
swing
.
JButton
();
jTextField3
=
new
javax
.
swing
.
JTextField
();
setDefaultCloseOperation
(
javax
.
swing
.
WindowConstants
.
EXIT_ON_CLOSE
);
setTitle
(
"Kalkulator"
);
setResizable
(
false
);
jTextField1
.
setFont
(
new
java
.
awt
.
Font
(
"Dialog"
,
1
,
36
));
// NOI18N
jTextField1
.
setHorizontalAlignment
(
javax
.
swing
.
JTextField
.
RIGHT
);
jTextField2
.
setFont
(
new
java
.
awt
.
Font
(
"Dialog"
,
1
,
36
));
// NOI18N
jTextField2
.
setHorizontalAlignment
(
javax
.
swing
.
JTextField
.
RIGHT
);
jComboBox1
.
setFont
(
new
java
.
awt
.
Font
(
"Dialog"
,
1
,
36
));
// NOI18N
jComboBox1
.
setModel
(
new
javax
.
swing
.
DefaultComboBoxModel
<>(
new
String
[]
{
"+"
,
"-"
,
"*"
,
"/"
}));
jComboBox1
.
addActionListener
(
new
java
.
awt
.
event
.
ActionListener
()
{
public
void
actionPerformed
(
java
.
awt
.
event
.
ActionEvent
evt
)
{
jComboBox1ActionPerformed
(
evt
);
}
});
jButton1
.
setFont
(
new
java
.
awt
.
Font
(
"Dialog"
,
1
,
36
));
// NOI18N
jButton1
.
setText
(
"Oblicz"
);
jButton1
.
addActionListener
(
new
java
.
awt
.
event
.
ActionListener
()
{
public
void
actionPerformed
(
java
.
awt
.
event
.
ActionEvent
evt
)
{
jButton1ActionPerformed
(
evt
);
}
});
jTextField3
.
setEditable
(
false
);
jTextField3
.
setFont
(
new
java
.
awt
.
Font
(
"Dialog"
,
1
,
36
));
// NOI18N
jTextField3
.
setHorizontalAlignment
(
javax
.
swing
.
JTextField
.
RIGHT
);
jTextField3
.
setText
(
"0"
);
javax
.
swing
.
GroupLayout
layout
=
new
javax
.
swing
.
GroupLayout
(
getContentPane
());
getContentPane
().
setLayout
(
layout
);
layout
.
setHorizontalGroup
(
layout
.
createParallelGroup
(
javax
.
swing
.
GroupLayout
.
Alignment
.
LEADING
)
.
addGroup
(
layout
.
createSequentialGroup
()
.
addContainerGap
()
.
addGroup
(
layout
.
createParallelGroup
(
javax
.
swing
.
GroupLayout
.
Alignment
.
LEADING
)
.
addGroup
(
layout
.
createSequentialGroup
()
.
addComponent
(
jButton1
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
,
415
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
)
.
addGap
(
169
,
169
,
169
)
.
addComponent
(
jTextField3
))
.
addGroup
(
layout
.
createSequentialGroup
()
.
addComponent
(
jTextField1
,
javax
.
swing
.
GroupLayout
.
DEFAULT_SIZE
,
414
,
Short
.
MAX_VALUE
)
.
addGap
(
18
,
18
,
18
)
.
addComponent
(
jComboBox1
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
,
133
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
)
.
addGap
(
18
,
18
,
18
)
.
addComponent
(
jTextField2
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
,
415
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
)))
.
addContainerGap
())
);
layout
.
linkSize
(
javax
.
swing
.
SwingConstants
.
HORIZONTAL
,
new
java
.
awt
.
Component
[]
{
jTextField1
,
jTextField2
});
layout
.
setVerticalGroup
(
layout
.
createParallelGroup
(
javax
.
swing
.
GroupLayout
.
Alignment
.
LEADING
)
.
addGroup
(
layout
.
createSequentialGroup
()
.
addContainerGap
()
.
addGroup
(
layout
.
createParallelGroup
(
javax
.
swing
.
GroupLayout
.
Alignment
.
BASELINE
)
.
addComponent
(
jTextField1
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
,
60
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
)
.
addComponent
(
jTextField2
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
,
javax
.
swing
.
GroupLayout
.
DEFAULT_SIZE
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
)
.
addComponent
(
jComboBox1
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
,
javax
.
swing
.
GroupLayout
.
DEFAULT_SIZE
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
))
.
addGap
(
18
,
18
,
18
)
.
addGroup
(
layout
.
createParallelGroup
(
javax
.
swing
.
GroupLayout
.
Alignment
.
BASELINE
)
.
addComponent
(
jButton1
)
.
addComponent
(
jTextField3
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
,
javax
.
swing
.
GroupLayout
.
DEFAULT_SIZE
,
javax
.
swing
.
GroupLayout
.
PREFERRED_SIZE
))
.
addContainerGap
(
20
,
Short
.
MAX_VALUE
))
);
layout
.
linkSize
(
javax
.
swing
.
SwingConstants
.
VERTICAL
,
new
java
.
awt
.
Component
[]
{
jButton1
,
jComboBox1
,
jTextField1
,
jTextField2
,
jTextField3
});
pack
();
}
// </editor-fold>//GEN-END:initComponents
private
void
jButton1ActionPerformed
(
java
.
awt
.
event
.
ActionEvent
evt
)
{
//GEN-FIRST:event_jButton1ActionPerformed
przelicz
();
}
//GEN-LAST:event_jButton1ActionPerformed
private
void
jComboBox1ActionPerformed
(
java
.
awt
.
event
.
ActionEvent
evt
)
{
//GEN-FIRST:event_jComboBox1ActionPerformed
przelicz
();
}
//GEN-LAST:event_jComboBox1ActionPerformed
private
void
przelicz
()
{
if
(
jTextField1
.
getText
().
isEmpty
()
||
jTextField2
.
getText
().
isEmpty
())
{
jTextField3
.
setText
(
""
);
}
else
try
{
long
liczba1
=
Long
.
parseLong
(
jTextField1
.
getText
());
long
liczba2
=
Long
.
parseLong
(
jTextField2
.
getText
());
// String operacja = jComboBox1.getItemAt(jComboBox1.getSelectedIndex());
String
operacja
=
(
String
)
jComboBox1
.
getSelectedItem
();
long
wynik
=
LogikaKalkulatora
.
oblicz
(
liczba1
,
liczba2
,
operacja
);
jTextField3
.
setText
(
String
.
valueOf
(
wynik
));
jTextField3
.
setForeground
(
Color
.
BLUE
);
}
catch
(
Exception
e
)
{
jTextField3
.
setText
(
"BŁĄD"
);
jTextField3
.
setForeground
(
Color
.
RED
);
}
}
/**
* @param args the command line arguments
*/
public
static
void
main
(
String
args
[])
{
/* Set the Nimbus look and feel */
//<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
/* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
* For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try
{
for
(
javax
.
swing
.
UIManager
.
LookAndFeelInfo
info
:
javax
.
swing
.
UIManager
.
getInstalledLookAndFeels
())
{
if
(
"Nimbus"
.
equals
(
info
.
getName
()))
{
javax
.
swing
.
UIManager
.
setLookAndFeel
(
info
.
getClassName
());
break
;
}
}
}
catch
(
ClassNotFoundException
ex
)
{
java
.
util
.
logging
.
Logger
.
getLogger
(
OknoKalkulatora4
.
class
.
getName
()).
log
(
java
.
util
.
logging
.
Level
.
SEVERE
,
null
,
ex
);
}
catch
(
InstantiationException
ex
)
{
java
.
util
.
logging
.
Logger
.
getLogger
(
OknoKalkulatora4
.
class
.
getName
()).
log
(
java
.
util
.
logging
.
Level
.
SEVERE
,
null
,
ex
);
}
catch
(
IllegalAccessException
ex
)
{
java
.
util
.
logging
.
Logger
.
getLogger
(
OknoKalkulatora4
.
class
.
getName
()).
log
(
java
.
util
.
logging
.
Level
.
SEVERE
,
null
,
ex
);
}
catch
(
javax
.
swing
.
UnsupportedLookAndFeelException
ex
)
{
java
.
util
.
logging
.
Logger
.
getLogger
(
OknoKalkulatora4
.
class
.
getName
()).
log
(
java
.
util
.
logging
.
Level
.
SEVERE
,
null
,
ex
);
}
//</editor-fold>
//</editor-fold>
/* Create and display the form */
java
.
awt
.
EventQueue
.
invokeLater
(
new
Runnable
()
{
public
void
run
()
{
new
OknoKalkulatora4
().
setVisible
(
true
);
}
});
}
// Variables declaration - do not modify//GEN-BEGIN:variables
private
javax
.
swing
.
JButton
jButton1
;
private
javax
.
swing
.
JComboBox
<
String
>
jComboBox1
;
private
javax
.
swing
.
JTextField
jTextField1
;
private
javax
.
swing
.
JTextField
jTextField2
;
private
javax
.
swing
.
JTextField
jTextField3
;
// End of variables declaration//GEN-END:variables
}
src/main/java/p30_swing/layout/Layout_Border.java
0 → 100644
View file @
c6f21c80
package
p30_swing
.
layout
;
import
java.awt.BorderLayout
;
import
java.awt.Font
;
import
javax.swing.JButton
;
import
javax.swing.JFrame
;
public
class
Layout_Border
{
private
final
static
Font
FONT
=
new
Font
(
"Arial"
,
Font
.
BOLD
,
30
);
public
static
void
main
(
String
[]
args
)
{
final
JFrame
okno
=
new
JFrame
();
okno
.
setDefaultCloseOperation
(
JFrame
.
EXIT_ON_CLOSE
);
BorderLayout
layout
=
new
BorderLayout
();
okno
.
setLayout
(
layout
);
final
JButton
button1
=
new
JButton
(
"A"
);
button1
.
setFont
(
FONT
);
okno
.
add
(
button1
,
BorderLayout
.
CENTER
);
final
JButton
button2
=
new
JButton
(
"B"
);
button2
.
setFont
(
FONT
);
okno
.
add
(
button2
,
BorderLayout
.
NORTH
);
final
JButton
button3
=
new
JButton
(
"C"
);
button3
.
setFont
(
FONT
);
okno
.
add
(
button3
,
BorderLayout
.
WEST
);
final
JButton
button4
=
new
JButton
(
"D"
);
button4
.
setFont
(
FONT
);
okno
.
add
(
button4
,
BorderLayout
.
EAST
);
okno
.
pack
();
okno
.
setVisible
(
true
);
}
}
src/main/java/p30_swing/layout/Layout_Box.java
0 → 100644
View file @
c6f21c80
package
p30_swing
.
layout
;
import
java.awt.Font
;
import
javax.swing.BoxLayout
;
import
javax.swing.JButton
;
import
javax.swing.JFrame
;
public
class
Layout_Box
{
private
final
static
Font
FONT
=
new
Font
(
"Arial"
,
Font
.
BOLD
,
30
);
public
static
void
main
(
String
[]
args
)
{
final
JFrame
okno
=
new
JFrame
();
okno
.
setDefaultCloseOperation
(
JFrame
.
EXIT_ON_CLOSE
);
BoxLayout
layout
=
new
BoxLayout
(
okno
.
getContentPane
(),
BoxLayout
.
X_AXIS
);
okno
.
setLayout
(
layout
);
final
JButton
button1
=
new
JButton
(
"A"
);
button1
.
setFont
(
FONT
);
okno
.
add
(
button1
);
final
JButton
button2
=
new
JButton
(
"B"
);
button2
.
setFont
(
FONT
);
okno
.
add
(
button2
);
final
JButton
button3
=
new
JButton
(
"C"
);
button3
.
setFont
(
FONT
);
okno
.
add
(
button3
);
final
JButton
button4
=
new
JButton
(
"D"
);
button4
.
setFont
(
FONT
);
okno
.
add
(
button4
);
okno
.
pack
();
okno
.
setVisible
(
true
);
}
}
src/main/java/p30_swing/layout/Layout_BoxY.java
0 → 100644
View file @
c6f21c80
package
p30_swing
.
layout
;
import
java.awt.Font
;
import
javax.swing.BoxLayout
;
import
javax.swing.JButton
;
import
javax.swing.JFrame
;
public
class
Layout_BoxY
{
private
final
static
Font
FONT
=
new
Font
(
"Arial"
,
Font
.
BOLD
,
30
);
public
static
void
main
(
String
[]
args
)
{
final
JFrame
okno
=
new
JFrame
();
okno
.
setDefaultCloseOperation
(
JFrame
.
EXIT_ON_CLOSE
);
BoxLayout
layout
=
new
BoxLayout
(
okno
.
getContentPane
(),
BoxLayout
.
Y_AXIS
);
okno
.
setLayout
(
layout
);
final
JButton
button1
=
new
JButton
(
"A"
);
button1
.
setFont
(
FONT
);
okno
.
add
(
button1
);
final
JButton
button2
=
new
JButton
(
"B"
);
button2
.
setFont
(
FONT
);
okno
.
add
(
button2
);
final
JButton
button3
=
new
JButton
(
"C"
);
button3
.
setFont
(
FONT
);
okno
.
add
(
button3
);
final
JButton
button4
=
new
JButton
(
"D"
);
button4
.
setFont
(
FONT
);
okno
.
add
(
button4
);
okno
.
pack
();
okno
.
setVisible
(
true
);
}
}
src/main/java/p30_swing/layout/Layout_Flow.java
0 → 100644
View file @
c6f21c80
package
p30_swing
.
layout
;
import
java.awt.FlowLayout
;
import
java.awt.Font
;
import
javax.swing.JButton
;
import
javax.swing.JFrame
;
public
class
Layout_Flow
{
private
final
static
Font
FONT
=
new
Font
(
"Arial"
,
Font
.
BOLD
,
30
);
public
static
void
main
(
String
[]
args
)
{
final
JFrame
okno
=
new
JFrame
();
okno
.
setDefaultCloseOperation
(
JFrame
.
EXIT_ON_CLOSE
);
FlowLayout
layout
=
new
FlowLayout
();
okno
.
setLayout
(
layout
);
final
JButton
button1
=
new
JButton
(
"A"
);
button1
.
setFont
(
FONT
);
okno
.
add
(
button1
);
final
JButton
button2
=
new
JButton
(
"B"
);
button2
.
setFont
(
FONT
);
okno
.
add
(
button2
);
final
JButton
button3
=
new
JButton
(
"C"
);
button3
.
setFont
(
FONT
);
okno
.
add
(
button3
);
final
JButton
button4
=
new
JButton
(
"D"
);
button4
.
setFont
(
FONT
);
okno
.
add
(
button4
);
final
JButton
button5
=
new
JButton
(
"E"
);
button5
.
setFont
(
FONT
);
okno
.
add
(
button5
);
final
JButton
button6
=
new
JButton
(
"F"
);
button6
.
setFont
(
FONT
);
okno
.
add
(
button6
);
final
JButton
button7
=
new
JButton
(
"G"
);
button7
.
setFont
(
FONT
);
okno
.
add
(
button7
);
final
JButton
button8
=
new
JButton
(
"H"
);
button8
.
setFont
(
FONT
);
okno
.
add
(
button8
);
okno
.
pack
();
okno
.
setVisible
(
true
);
}
}
src/main/java/p30_swing/layout/Layout_Flow2.java
0 → 100644
View file @
c6f21c80
package
p30_swing
.
layout
;
import
java.awt.FlowLayout
;
import
java.awt.Font
;
import
javax.swing.JButton
;
import
javax.swing.JFrame
;
public
class
Layout_Flow2
{
private
final
static
Font
FONT
=
new
Font
(
"Arial"
,
Font
.
BOLD
,
30
);
public
static
void
main
(
String
[]
args
)
{
final
JFrame
okno
=
new
JFrame
();
okno
.
setDefaultCloseOperation
(
JFrame
.
EXIT_ON_CLOSE
);
FlowLayout
layout
=
new
FlowLayout
(
FlowLayout
.
RIGHT
,
10
,
10
);
okno
.
setLayout
(
layout
);
final
JButton
button1
=
new
JButton
(
"A"
);
button1
.
setFont
(
FONT
);
okno
.
add
(
button1
);
final
JButton
button2
=
new
JButton
(
"B"
);
button2
.
setFont
(
FONT
);
okno
.
add
(
button2
);
final
JButton
button3
=
new
JButton
(
"C"
);
button3
.
setFont
(
FONT
);
okno
.
add
(
button3
);
final
JButton
button4
=
new
JButton
(
"D"
);
button4
.
setFont
(
FONT
);
okno
.
add
(
button4
);
final
JButton
button5
=
new
JButton
(
"E"
);
button5
.
setFont
(
FONT
);
okno
.
add
(
button5
);
final
JButton
button6
=
new
JButton
(
"F"
);
button6
.
setFont
(
FONT
);
okno
.
add
(
button6
);
final
JButton
button7
=
new
JButton
(
"G"
);
button7
.
setFont
(
FONT
);
okno
.
add
(
button7
);
final
JButton
button8
=
new
JButton
(
"H"
);
button8
.
setFont
(
FONT
);
okno
.
add
(
button8
);
okno
.
pack
();
okno
.
setVisible
(
true
);
}
}
src/main/java/p30_swing/layout/Layout_Grid.java
0 → 100644
View file @
c6f21c80
package
p30_swing
.
layout
;
import
java.awt.Font
;
import
java.awt.GridLayout
;
import
javax.swing.JButton
;
import
javax.swing.JFrame
;
public
class
Layout_Grid
{
private
final
static
Font
FONT
=
new
Font
(
"Arial"
,
Font
.
BOLD
,
30
);
public
static
void
main
(
String
[]
args
)
{
final
JFrame
okno
=
new
JFrame
();
okno
.
setDefaultCloseOperation
(
JFrame
.
EXIT_ON_CLOSE
);
GridLayout
layout
=
new
GridLayout
(
2
,
4
,
10
,
20
);
okno
.
setLayout
(
layout
);
final
JButton
button1
=
new
JButton
(
"A"
);
button1
.
setFont
(
FONT
);
okno
.
add
(
button1
);
final
JButton
button2
=
new
JButton
(
"B"
);
button2
.
setFont
(
FONT
);
okno
.
add
(
button2
);
final
JButton
button3
=
new
JButton
(
"C"
);
button3
.
setFont
(
FONT
);
okno
.
add
(
button3
);
final
JButton
button4
=
new
JButton
(
"D"
);
button4
.
setFont
(
FONT
);
okno
.
add
(
button4
);
final
JButton
button5
=
new
JButton
(
"E"
);
button5
.
setFont
(
FONT
);
okno
.
add
(
button5
);
final
JButton
button6
=
new
JButton
(
"F"
);
button6
.
setFont
(
FONT
);
okno
.
add
(
button6
);
final
JButton
button7
=
new
JButton
(
"G"
);
button7
.
setFont
(
FONT
);
okno
.
add
(
button7
);
final
JButton
button8
=
new
JButton
(
"H"
);
button8
.
setFont
(
FONT
);
okno
.
add
(
button8
);
final
JButton
button9
=
new
JButton
(
"J"
);
button9
.
setFont
(
FONT
);
okno
.
add
(
button9
);
okno
.
pack
();
okno
.
setVisible
(
true
);
}
}
src/main/java/p30_swing/layout/WypiszDostepneStyle.java
0 → 100644
View file @
c6f21c80
package
p30_swing
.
layout
;
public
class
WypiszDostepneStyle
{
public
static
void
main
(
String
[]
args
)
{
System
.
out
.
println
(
"Oto dostępne style dla Swinga:"
);
for
(
javax
.
swing
.
UIManager
.
LookAndFeelInfo
info
:
javax
.
swing
.
UIManager
.
getInstalledLookAndFeels
())
{
System
.
out
.
println
(
" * "
+
info
.
getName
());
}
}
}
src/main/java/p30_swing/zdarzenia/Rozmowa_Obiektowo.java
0 → 100644
View file @
c6f21c80
package
p30_swing
.
zdarzenia
;
import
java.awt.Color
;
import
java.awt.Dimension
;
import
java.awt.Font
;
import
java.awt.LayoutManager
;
import
java.awt.event.ActionEvent
;
import
java.awt.event.ActionListener
;
import
java.util.Random
;
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
;
// Ta wersja jest porządniej napisania
// - zmienne nie są definiowane w mainie, tylko są polami obiektu.
// Dzięki temu jest do nich łatwy dostep z róznych metod.
// Aby uruchomić program, tworzony jest obiekt tej klasy.
public
class
Rozmowa_Obiektowo
{
private
static
final
Font
FONT
=
new
Font
(
"Arial"
,
Font
.
BOLD
,
32
);
private
static
final
Dimension
odstep
=
new
Dimension
(
0
,
10
);
private
JFrame
okno
;
private
JPanel
panel
;
private
JLabel
pytanie
;
private
JTextField
pole
;
private
JButton
guzik
;
private
JLabel
powitanie
;
private
JButton
guzik2
;
public
static
void
main
(
String
[]
args
)
{
new
Rozmowa_Obiektowo
().
run
();
}
public
void
run
()
{
przygotujWyglad
();
przygotujZdarzenia
();
wyswietl
();
System
.
out
.
println
(
"okno wyświetlone, koniec main"
);
}
private
void
przygotujWyglad
()
{
okno
=
new
JFrame
(
"Rozmowa"
);
okno
.
setDefaultCloseOperation
(
JFrame
.
EXIT_ON_CLOSE
);
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
);
pytanie
=
new
JLabel
(
"Jak masz na imię?"
);
pytanie
.
setFont
(
FONT
);
pytanie
.
setForeground
(
Color
.
BLACK
);
panel
.
add
(
pytanie
);
panel
.
add
(
Box
.
createRigidArea
(
odstep
));
pole
=
new
JTextField
();
pole
.
setFont
(
FONT
);
pole
.
setForeground
(
Color
.
RED
);
panel
.
add
(
pole
);
panel
.
add
(
Box
.
createRigidArea
(
odstep
));
guzik
=
new
JButton
(
"OK"
);
guzik
.
setFont
(
FONT
);
guzik
.
setMaximumSize
(
new
Dimension
(
Integer
.
MAX_VALUE
,
30
));
panel
.
add
(
guzik
);
panel
.
add
(
Box
.
createRigidArea
(
odstep
));
powitanie
=
new
JLabel
(
"Witaj"
);
powitanie
.
setFont
(
FONT
);
powitanie
.
setForeground
(
Color
.
BLUE
);
panel
.
add
(
powitanie
);
panel
.
add
(
Box
.
createRigidArea
(
odstep
));
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
();
}
private
void
wyswietl
()
{
okno
.
setVisible
(
true
);
}
private
void
przygotujZdarzenia
()
{
// aby obsługiwać zdarzenia, tworzymy obiekt listener i rejestrujemy go w guziku
// MojListener listener = new MojListener();
// guzik.addActionListener(listener);
// w praktyce listenery najczęściej tworzy się bezpośrednio w klasie okna
// za pomocą składni "klasa anonimowa" (lub od Javy 8 - "wyrażenie lambda")
guzik
.
addActionListener
(
new
ActionListener
()
{
public
void
actionPerformed
(
ActionEvent
e
)
{
// Dzięki temu, że teraz jestem w tej samej klasie i mam dostęp do zmiennych
// pole, guzik itp., mogę zmienić zawartość i wygląd okna.
String
imie
=
pole
.
getText
();
powitanie
.
setText
(
"Witaj "
+
imie
);
powitanie
.
setForeground
(
Color
.
BLUE
);
}
});
// Również do pola tekstowego można dodać obsługę zdarzeń - to będzie zdarzenie "naciśnięcia ENTER"
pole
.
addActionListener
(
evt
->
{
String
imie
=
pole
.
getText
();
powitanie
.
setText
(
"Halo "
+
imie
);
powitanie
.
setForeground
(
Color
.
GREEN
);
});
Random
random
=
new
Random
();
guzik2
.
addActionListener
(
new
ActionListener
()
{
public
void
actionPerformed
(
ActionEvent
e
)
{
powitanie
.
setForeground
(
Color
.
GREEN
);
okno
.
getContentPane
().
setBackground
(
new
Color
(
random
.
nextInt
(
0x1000000
)));
int
x
=
okno
.
getX
()
+
random
.
nextInt
(
400
)
-
200
;
int
y
=
okno
.
getY
()
+
random
.
nextInt
(
400
)
-
200
;
okno
.
setLocation
(
x
,
y
);
}
});
}
}
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