Yam Code
Sign up
Login
New paste
Home
Trending
Archive
English
English
Tiếng Việt
भारत
Sign up
Login
New Paste
Browse
/* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package GiaiPTBac1; import java.awt.*; import java.awt.event.*; import javax.swing.*; /** * * @author Admin */ public class View extends JFrame { private JTextField tfHeSoA, tfHeSoB, tfKetQua; private JButton btnGiai, btnXoa, btnThoat; public View() { this.initComponents(); this.ActionListener(); } private void initComponents() { this.setTitle("Giải Phương Trình Bậc 1"); this.setSize(500, 400); this.setLocationRelativeTo(null); this.setDefaultCloseOperation(EXIT_ON_CLOSE); Container con = this.getContentPane(); con.setLayout(new BoxLayout(con, BoxLayout.Y_AXIS)); JPanel[] listPanel = new JPanel[5]; FlowLayout flowL = new FlowLayout(FlowLayout.CENTER); for (int i = 0; i < listPanel.length; i++) { listPanel[i] = new JPanel(); } // Panel[0] - Tiêu Đề listPanel[0].setLayout(flowL); JLabel lbTieuDe = new JLabel("Giải Phương Trình Bậc 1"); listPanel[0].add(lbTieuDe); // Panel[1] - Hệ Số A listPanel[1].setLayout(flowL); JLabel lbHeSoA = new JLabel("Hệ Số A: "); tfHeSoA = new JTextField(20); listPanel[1].add(lbHeSoA); listPanel[1].add(tfHeSoA); // Panel[2] - Hệ Số B listPanel[2].setLayout(flowL); JLabel lbHeSoB = new JLabel("Hệ Số B: "); tfHeSoB = new JTextField(20); listPanel[2].add(lbHeSoB); listPanel[2].add(tfHeSoB); // Panel[3] - Nút listPanel[3].setLayout(flowL); btnXoa = new JButton("Xóa"); btnGiai = new JButton("Giải"); btnThoat = new JButton("Thoát"); listPanel[3].add(btnGiai); listPanel[3].add(btnXoa); listPanel[3].add(btnThoat); // Panel[4] - Kết Quả listPanel[4].setLayout(flowL); JLabel lbKetQua = new JLabel("Kết Quả: "); tfKetQua = new JTextField(20); tfKetQua.setEnabled(false); listPanel[4].add(lbKetQua); listPanel[4].add(tfKetQua); // Add Panel to Container for (JPanel panel : listPanel) { con.add(panel); } } private void ActionListener() { btnGiai.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (!View.isNumeric(tfHeSoA.getText()) || !View.isNumeric(tfHeSoB.getText())) { tfKetQua.setText("Vui lòng nhập lại A hoặc B"); } else { Double a = Double.parseDouble(tfHeSoA.getText()); Double b = Double.parseDouble(tfHeSoB.getText()); if (a == 0 && b == 0) { tfKetQua.setText("Phương Trình Vô Số Nghiệm"); } else if (a == 0 && b != 0) { tfKetQua.setText("Phương Trình Vô Nghiệm"); } else { tfKetQua.setText("Phương Trình Có Nghiệm x=" + (-b / a)); } } } }); btnXoa.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { tfHeSoA.setText(""); tfHeSoB.setText(""); tfKetQua.setText(""); tfHeSoA.requestFocus(); } }); btnThoat.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { int n = JOptionPane.showConfirmDialog(null, "Bạn muốn thoát không?", "Thông Báo", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE); if(n == JOptionPane.YES_OPTION) System.exit(0); else JOptionPane.showMessageDialog(null, "Vậy ớ hở"); } }); } public static boolean isNumeric(String strNum) { if (strNum == null) { return false; } try { double d = Double.parseDouble(strNum); } catch (NumberFormatException nfe) { return false; } return true; } public static void main(String[] args) { new View().setVisible(true); } }
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
भारत