Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
T
test
Project
Project
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
9531703
test
Commits
97498a94
Commit
97498a94
authored
Dec 17, 2018
by
9531703
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
version 1
parents
Pipeline
#48
failed with stages
Changes
3
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
318 additions
and
0 deletions
+318
-0
CalculatorGUI.java
CalculatorGUI.java
+309
-0
Main.java
Main.java
+9
-0
README.md
README.md
+0
-0
No files found.
CalculatorGUI.java
0 → 100644
View file @
97498a94
package
com
.
company
;
import
javax.swing.*
;
import
java.awt.*
;
import
java.awt.event.ActionEvent
;
import
java.awt.event.ActionListener
;
import
java.awt.event.KeyEvent
;
import
java.awt.event.KeyListener
;
public
class
CalculatorGUI
implements
ActionListener
,
KeyListener
{
JFrame
calcFrame
;
public
JTextArea
display
;
protected
int
a
,
b
,
cs
;
public
CalculatorGUI
(){
calcFrame
=
new
JFrame
();
calcFrame
.
setTitle
(
"AUT Calculator"
);
calcFrame
.
setSize
(
350
,
370
);
calcFrame
.
setLocation
(
100
,
200
);
JMenuBar
menuBar
=
new
JMenuBar
();
JMenu
fileMenu
=
new
JMenu
(
"File"
);
fileMenu
.
setMnemonic
(
'F'
);
JMenuItem
exitItem
=
new
JMenuItem
(
"Exit"
);
// create exit item
exitItem
.
setMnemonic
(
'x'
);
exitItem
.
addActionListener
(
new
ActionListener
()
{
public
void
actionPerformed
(
ActionEvent
ev
)
{
System
.
exit
(
0
);
}
});
fileMenu
.
add
(
exitItem
);
menuBar
.
add
(
fileMenu
);
//calcFrame.add(menuBar);
JPanel
keyboardPanel
=
new
JPanel
();
keyboardPanel
.
setLayout
(
new
GridLayout
(
5
,
3
));
display
=
new
JTextArea
(
3
,
10
);
display
.
setEditable
(
false
);
display
.
setToolTipText
(
"for displaying"
);
display
.
setFont
(
new
Font
(
"Arial"
,
14
,
14
));
display
.
setBackground
(
Color
.
GREEN
);
for
(
int
i
=
9
;
i
>
0
;
i
--)
{
JButton
btn
=
new
JButton
();
btn
.
setText
(
""
+
i
);
btn
.
setToolTipText
(
"number "
+
i
);
btn
.
setFocusable
(
true
);
btn
.
addActionListener
(
this
);
btn
.
addKeyListener
(
this
);
keyboardPanel
.
add
(
btn
);
}
JButton
sumBtn
=
new
JButton
();
sumBtn
.
setText
(
"+"
);
sumBtn
.
setToolTipText
(
"btn +"
);
sumBtn
.
setFocusable
(
true
);
sumBtn
.
addKeyListener
(
this
);
sumBtn
.
addActionListener
(
this
);
keyboardPanel
.
add
(
sumBtn
);
JButton
zeroBtn
=
new
JButton
();
zeroBtn
.
setText
(
"0"
);
zeroBtn
.
setToolTipText
(
"number 0"
);
zeroBtn
.
setFocusable
(
true
);
zeroBtn
.
addKeyListener
(
this
);
zeroBtn
.
addActionListener
(
this
);
keyboardPanel
.
add
(
zeroBtn
);
JButton
doBtn
=
new
JButton
();
doBtn
.
setText
(
"="
);
doBtn
.
setToolTipText
(
"btn ="
);
doBtn
.
setFocusable
(
true
);
doBtn
.
addKeyListener
(
this
);
doBtn
.
addActionListener
(
this
);
keyboardPanel
.
add
(
doBtn
);
JButton
mulBtn
=
new
JButton
();
mulBtn
.
setText
(
"*"
);
mulBtn
.
setToolTipText
(
"btn *"
);
mulBtn
.
setFocusable
(
true
);
mulBtn
.
addKeyListener
(
this
);
mulBtn
.
addActionListener
(
this
);
keyboardPanel
.
add
(
mulBtn
);
JButton
divideBtn
=
new
JButton
();
divideBtn
.
setText
(
"/"
);
divideBtn
.
setToolTipText
(
"btn /"
);
divideBtn
.
setFocusable
(
true
);
divideBtn
.
addKeyListener
(
this
);
divideBtn
.
addActionListener
(
this
);
keyboardPanel
.
add
(
divideBtn
);
JButton
subBtn
=
new
JButton
();
subBtn
.
setText
(
"-"
);
subBtn
.
setToolTipText
(
"btn -"
);
subBtn
.
addActionListener
(
this
);
keyboardPanel
.
add
(
subBtn
);
JPanel
totalOne
=
new
JPanel
();
totalOne
.
setSize
(
350
,
370
);
totalOne
.
setLayout
(
new
GridLayout
(
2
,
1
));
totalOne
.
add
(
display
);
totalOne
.
add
(
keyboardPanel
);
JTabbedPane
tp
=
new
JTabbedPane
();
totalOne
.
addKeyListener
(
this
);
tp
.
add
(
"manual"
,
totalOne
);
tp
.
addKeyListener
(
this
);
//--------------------------------------------------------------
JPanel
keyboardPanel2
=
new
JPanel
();
keyboardPanel2
.
setLayout
(
new
GridLayout
(
6
,
3
));
for
(
int
i
=
9
;
i
>
0
;
i
--)
{
JButton
btn
=
new
JButton
();
btn
.
setText
(
""
+
i
);
keyboardPanel2
.
add
(
btn
);
}
JButton
sumBtn2
=
new
JButton
();
sumBtn2
.
setText
(
"+"
);
keyboardPanel2
.
add
(
sumBtn2
);
JButton
zeroBtn2
=
new
JButton
();
zeroBtn2
.
setText
(
"0"
);
keyboardPanel2
.
add
(
zeroBtn2
);
JButton
doBtn2
=
new
JButton
();
doBtn2
.
setText
(
"="
);
keyboardPanel2
.
add
(
doBtn2
);
JButton
mulBtn2
=
new
JButton
();
mulBtn2
.
setText
(
"*"
);
keyboardPanel2
.
add
(
mulBtn2
);
JButton
divideBtn2
=
new
JButton
();
divideBtn2
.
setText
(
"="
);
keyboardPanel2
.
add
(
divideBtn2
);
JButton
subBtn2
=
new
JButton
();
subBtn2
.
setText
(
"-"
);
keyboardPanel2
.
add
(
subBtn2
);
JButton
sinBtn
=
new
JButton
();
sinBtn
.
setText
(
"sin / cos"
);
keyboardPanel2
.
add
(
sinBtn
);
JButton
tanBtn
=
new
JButton
();
tanBtn
.
setText
(
"tan / cot"
);
keyboardPanel2
.
add
(
tanBtn
);
JButton
logBtn
=
new
JButton
();
logBtn
.
setText
(
"log / exp"
);
keyboardPanel2
.
add
(
logBtn
);
JTextArea
display2
=
new
JTextArea
(
3
,
10
);
display2
.
setEditable
(
false
);
display2
.
setFont
(
new
Font
(
"Arial"
,
14
,
14
));
display2
.
setBackground
(
Color
.
GREEN
);
JButton
shBtn
=
new
JButton
(
"Shift"
);
shBtn
.
setBackground
(
Color
.
RED
);
JPanel
totalTwo
=
new
JPanel
();
totalTwo
.
setLayout
(
new
GridLayout
(
3
,
1
));
totalTwo
.
add
(
display2
);
totalTwo
.
add
(
keyboardPanel2
);
totalTwo
.
add
(
shBtn
);
tp
.
add
(
"engenering"
,
totalTwo
);
calcFrame
.
add
(
menuBar
,
BorderLayout
.
NORTH
);
calcFrame
.
add
(
tp
,
BorderLayout
.
CENTER
);
//calcFrame.setLayout(null);
calcFrame
.
setDefaultCloseOperation
(
JFrame
.
EXIT_ON_CLOSE
);
calcFrame
.
setVisible
(
true
);
}
@Override
public
void
actionPerformed
(
ActionEvent
e
)
{
JButton
btn
=
(
JButton
)
e
.
getSource
();
String
s
=
btn
.
getText
();
if
(
s
!=
"+"
&&
s
!=
"-"
&&
s
!=
"/"
&&
s
!=
"="
&&
s
!=
"*"
)
{
display
.
setText
(
display
.
getText
()
+
s
);
}
switch
(
s
){
case
"+"
:
a
=
Integer
.
parseInt
(
display
.
getText
());
display
.
setText
(
""
);
cs
=
1
;
break
;
case
"-"
:
a
=
Integer
.
parseInt
(
display
.
getText
());
display
.
setText
(
""
);
cs
=
2
;
break
;
case
"/"
:
a
=
Integer
.
parseInt
(
display
.
getText
());
display
.
setText
(
""
);
cs
=
3
;
break
;
case
"*"
:
a
=
Integer
.
parseInt
(
display
.
getText
());
display
.
setText
(
""
);
cs
=
4
;
break
;
case
"="
:
b
=
Integer
.
parseInt
(
display
.
getText
());
if
(
cs
==
1
)
display
.
setText
(
""
+
(
a
+
b
));
else
if
(
cs
==
2
)
display
.
setText
(
""
+
(
a
-
b
));
else
if
(
cs
==
3
)
display
.
setText
(
""
+
(
a
/
b
));
else
if
(
cs
==
4
)
display
.
setText
(
""
+
(
a
*
b
));
break
;
}
}
@Override
public
void
keyTyped
(
KeyEvent
e
)
{
}
@Override
public
void
keyPressed
(
KeyEvent
e
)
{
}
@Override
public
void
keyReleased
(
KeyEvent
e
)
{
int
kRealeased
=
e
.
getKeyCode
();
switch
(
kRealeased
){
case
KeyEvent
.
VK_NUMPAD1
:
display
.
setText
(
display
.
getText
()+
"1"
);
break
;
case
KeyEvent
.
VK_NUMPAD2
:
display
.
setText
(
display
.
getText
()+
"2"
);
break
;
case
KeyEvent
.
VK_NUMPAD3
:
display
.
setText
(
display
.
getText
()+
"3"
);
break
;
case
KeyEvent
.
VK_NUMPAD4
:
display
.
setText
(
display
.
getText
()+
"4"
);
break
;
case
KeyEvent
.
VK_NUMPAD5
:
display
.
setText
(
display
.
getText
()+
"5"
);
break
;
case
KeyEvent
.
VK_NUMPAD6
:
display
.
setText
(
display
.
getText
()+
"6"
);
break
;
case
KeyEvent
.
VK_NUMPAD7
:
display
.
setText
(
display
.
getText
()+
"7"
);
break
;
case
KeyEvent
.
VK_NUMPAD8
:
display
.
setText
(
display
.
getText
()+
"8"
);
break
;
case
KeyEvent
.
VK_NUMPAD9
:
display
.
setText
(
display
.
getText
()+
"9"
);
break
;
case
KeyEvent
.
VK_NUMPAD0
:
display
.
setText
(
display
.
getText
()+
"0"
);
break
;
case
KeyEvent
.
VK_ADD
:
a
=
Integer
.
parseInt
(
display
.
getText
());
display
.
setText
(
""
);
cs
=
1
;
break
;
case
KeyEvent
.
VK_SUBTRACT
:
a
=
Integer
.
parseInt
(
display
.
getText
());
display
.
setText
(
""
);
cs
=
2
;
break
;
case
KeyEvent
.
VK_DIVIDE
:
a
=
Integer
.
parseInt
(
display
.
getText
());
display
.
setText
(
""
);
cs
=
3
;
break
;
case
KeyEvent
.
VK_MULTIPLY
:
a
=
Integer
.
parseInt
(
display
.
getText
());
display
.
setText
(
""
);
cs
=
4
;
break
;
case
KeyEvent
.
VK_EQUALS
:
b
=
Integer
.
parseInt
(
display
.
getText
());
if
(
cs
==
1
)
display
.
setText
(
""
+
(
a
+
b
));
else
if
(
cs
==
2
)
display
.
setText
(
""
+
(
a
-
b
));
else
if
(
cs
==
3
)
display
.
setText
(
""
+
(
a
/
b
));
else
if
(
cs
==
4
)
display
.
setText
(
""
+
(
a
*
b
));
break
;
}
}
}
Main.java
0 → 100644
View file @
97498a94
package
com
.
company
;
public
class
Main
{
public
static
void
main
(
String
[]
args
)
{
CalculatorGUI
calculator
=
new
CalculatorGUI
();
}
}
README.md
0 → 100644
View file @
97498a94
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