Yam Code
Sign up
Login
New paste
Home
Trending
Archive
English
English
Tiếng Việt
भारत
Sign up
Login
New Paste
Browse
package CongTruNhanChia; import javax.swing.*; import java.awt.*; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import static javax.swing.GroupLayout.Alignment.BASELINE; import static javax.swing.GroupLayout.Alignment.TRAILING; public class UI extends JFrame { JTextField txtHeSoA,txtHeSoB,txtKetQua; ButtonGroup btnGroupPhepTinh; JRadioButton radioCong,radioTru,radioNhan,radioChia; JButton btnGiai,btnXoa,btnThoat; public UI(){ initComponent(); initListenEvent(); } /** * Create JFrame */ private void initComponent() { // Setup JFrame this.setSize(600,400); this.setTitle("Cộng Trừ Nhân Chia"); this.setDefaultCloseOperation(EXIT_ON_CLOSE); this.setLocationRelativeTo(null); // Setup Container Container con = getContentPane(); // Setup JPanel Title JPanel panelTitle = new JPanel(new FlowLayout()); panelTitle.setBackground(Color.decode("#73C6B6")); //// JLabel - Title JLabel labelTitle = new JLabel("Cộng Trừ Nhân Chia"); labelTitle.setFont(new Font("Arial",Font.BOLD,24)); panelTitle.add(labelTitle); // Setup JPanel Content JPanel panelContent = new JPanel(); GroupLayout GL = new GroupLayout(panelContent); panelContent.setLayout(GL); panelContent.setBorder(BorderFactory.createTitledBorder("nhập 2 số a và b")); //// Setup TextField - HeSoA JLabel labelHeSoA = new JLabel("a:"); txtHeSoA = new JTextField(25); //// Setup TextField - HeSoB JLabel labelHeSoB = new JLabel("b:"); txtHeSoB = new JTextField(25); //// Setup TextField - KetQua JLabel labelKetQua= new JLabel("Kết Quả:"); txtKetQua = new JTextField(25); //// Setup JPanel Cong Tru Nhan Chia JPanel panelPhepTinh = new JPanel(new GridLayout(2,2)); panelPhepTinh.setPreferredSize(new Dimension(100,50)); panelPhepTinh.setBorder(BorderFactory.createTitledBorder("Chọn phép toán")); //// Setup JRadioButton Group btnGroupPhepTinh = new ButtonGroup(); radioCong = new JRadioButton("Cộng",true); radioTru = new JRadioButton("Trừ"); radioNhan = new JRadioButton("Nhân"); radioChia = new JRadioButton("Chia"); btnGroupPhepTinh.add(radioCong); btnGroupPhepTinh.add(radioTru); btnGroupPhepTinh.add(radioNhan); btnGroupPhepTinh.add(radioChia); panelPhepTinh.add(radioCong); panelPhepTinh.add(radioTru); panelPhepTinh.add(radioNhan); panelPhepTinh.add(radioChia); // Add Component into JPanel TextField GL.setAutoCreateGaps(true); GL.setAutoCreateContainerGaps(true); GL.setHorizontalGroup(GL.createSequentialGroup() .addGroup(GL.createParallelGroup(TRAILING) .addComponent(labelHeSoA) .addComponent(labelHeSoB) .addComponent(labelKetQua)) .addGroup(GL.createParallelGroup() .addComponent(txtHeSoA) .addComponent(txtHeSoB) .addComponent(panelPhepTinh) .addComponent(txtKetQua)) ); GL.setVerticalGroup(GL.createSequentialGroup() .addGroup(GL.createParallelGroup(BASELINE) .addComponent(labelHeSoA) .addComponent(txtHeSoA)) .addGroup(GL.createParallelGroup(BASELINE) .addComponent(labelHeSoB) .addComponent(txtHeSoB)) .addGroup(GL.createParallelGroup(BASELINE) .addComponent(panelPhepTinh)) .addGroup(GL.createParallelGroup(BASELINE) .addComponent(labelKetQua) .addComponent(txtKetQua)) ); // Setup JPanel Button JPanel panelButton = new JPanel(); panelButton.setLayout(new GridLayout(10,1,10,0)); panelButton.setBorder(BorderFactory.createTitledBorder("Chọn thao tác")); //Setup Button btnGiai = new JButton("Giải"); btnXoa = new JButton("Xóa trắng"); btnThoat = new JButton("Thoát"); //Add Component into JPanel Button panelButton.add(btnGiai); panelButton.add(btnXoa); panelButton.add(btnThoat); // Setup JPanel JPanel panelEnd = new JPanel(new FlowLayout()); panelEnd.setBackground(Color.decode("#CD6155")); panelEnd.setPreferredSize(new Dimension(100,50)); // Add Component into Container con.add(panelTitle,BorderLayout.NORTH); con.add(panelButton,BorderLayout.WEST); con.add(panelContent,BorderLayout.CENTER); con.add(panelEnd,BorderLayout.SOUTH); pack(); } /** * Create Event */ private void initListenEvent() { btnThoat.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { System.exit(0); }; }); btnXoa.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { txtHeSoA.setText(""); txtHeSoB.setText(""); txtKetQua.setText(""); txtHeSoA.setRequestFocusEnabled(true); } }); btnGiai.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { Double A,B,C; try { A = Double.parseDouble(txtHeSoA.getText()); B = Double.parseDouble(txtHeSoB.getText()); if(radioCong.isSelected()) { txtKetQua.setText(""+(A+B)); }else if(radioTru.isSelected()){ txtKetQua.setText(""+(A-B)); }else if(radioNhan.isSelected()){ txtKetQua.setText(""+(A*B)); }else{ txtKetQua.setText(""+(A/B)); } } catch (Exception error) { JOptionPane.showMessageDialog(null,"Vui lòng nhập lại","Thông Báo",JOptionPane.INFORMATION_MESSAGE); } } }); } }
Paste Settings
Paste Title :
[Optional]
Paste Folder :
[Optional]
Select
Syntax Highlighting :
[Optional]
Select
Markup
CSS
JavaScript
Bash
C
C#
C++
Java
JSON
Lua
Plaintext
C-like
ABAP
ActionScript
Ada
Apache Configuration
APL
AppleScript
Arduino
ARFF
AsciiDoc
6502 Assembly
ASP.NET (C#)
AutoHotKey
AutoIt
Basic
Batch
Bison
Brainfuck
Bro
CoffeeScript
Clojure
Crystal
Content-Security-Policy
CSS Extras
D
Dart
Diff
Django/Jinja2
Docker
Eiffel
Elixir
Elm
ERB
Erlang
F#
Flow
Fortran
GEDCOM
Gherkin
Git
GLSL
GameMaker Language
Go
GraphQL
Groovy
Haml
Handlebars
Haskell
Haxe
HTTP
HTTP Public-Key-Pins
HTTP Strict-Transport-Security
IchigoJam
Icon
Inform 7
INI
IO
J
Jolie
Julia
Keyman
Kotlin
LaTeX
Less
Liquid
Lisp
LiveScript
LOLCODE
Makefile
Markdown
Markup templating
MATLAB
MEL
Mizar
Monkey
N4JS
NASM
nginx
Nim
Nix
NSIS
Objective-C
OCaml
OpenCL
Oz
PARI/GP
Parser
Pascal
Perl
PHP
PHP Extras
PL/SQL
PowerShell
Processing
Prolog
.properties
Protocol Buffers
Pug
Puppet
Pure
Python
Q (kdb+ database)
Qore
R
React JSX
React TSX
Ren'py
Reason
reST (reStructuredText)
Rip
Roboconf
Ruby
Rust
SAS
Sass (Sass)
Sass (Scss)
Scala
Scheme
Smalltalk
Smarty
SQL
Soy (Closure Template)
Stylus
Swift
TAP
Tcl
Textile
Template Toolkit 2
Twig
TypeScript
VB.Net
Velocity
Verilog
VHDL
vim
Visual Basic
WebAssembly
Wiki markup
Xeora
Xojo (REALbasic)
XQuery
YAML
HTML
Paste Expiration :
[Optional]
Never
Self Destroy
10 Minutes
1 Hour
1 Day
1 Week
2 Weeks
1 Month
6 Months
1 Year
Paste Status :
[Optional]
Public
Unlisted
Private (members only)
Password :
[Optional]
Description:
[Optional]
Tags:
[Optional]
Encrypt Paste
(
?
)
Create New Paste
You are currently not logged in, this means you can not edit or delete anything you paste.
Sign Up
or
Login
Site Languages
×
English
Tiếng Việt
भारत