Pastebin
API
tools
faq
paste
Login
Sign up
Please fix the following errors:
New Paste
Syntax Highlighting
import java.awt.*; import java.awt.event.*; import javax.swing.*; public class Lab9_1 extends JFrame implements ActionListener { Student std[]; SubjectNew sub[]; String studentStr[], subjectStr[]; Container container; JComboBox stdCombo, subCombo; JLabel stdLabel, subLabel, addsubLabel, codeLabel, nameLabel, creditLabel; JLabel addstdLabel, stdcodeLabel, stdnameLabel, stdsurnameLabel; JButton addstdBtn, addsubBtn, saveBtn, clearBtn, cancleBtn; JButton addnewsubBtn, editsubBtn, deletesubBtn, clearsubBtn; JButton addnewstdBtn, editstdBtn, deletestdBtn, clearstdBtn; JTextField stdText, codeText, nameText, creditText, statusText; JTextField stdcodeText, stdnameText, stdsurnameText, stdstatusText; JTextArea subTextArea, subTextArea2, stdTextArea; JScrollPane subScroll, subScroll2; Register reg; int count = 0, money_total = 0, credit_total = 0; final int submax = 12, stdmax = 5; static Lab9_1 a; public Lab9_1() { super("ลงทะเบียน"); initStudent(); initSubject(); initGui(); reg = new Register(new Student(), 5); statusText.setText("Number Object : " + SubjectNew.getCount()); stdstatusText.setText("Number Object : " + Student.getCount()); subTextArea2.setText(readString(sub)); stdTextArea.setText(readString(std)); } public Lab9_1(Lab9_1 a) { super("ลงทะเบียน"); this.a = a; initStudent(); initSubject(); initGui(); reg = new Register(new Student(), 5); statusText.setText("Number Object : " + SubjectNew.getCount()); stdstatusText.setText("Number Object : " + Student.getCount()); subTextArea2.setText(readString(sub)); stdTextArea.setText(readString(std)); } public void initStudent() { std = new Student[stdmax]; studentStr = new String[stdmax]; std[0] = new Student("6066260010", "Pankamol", "Kaewboon"); std[1] = new Student("6066260024", "Wikanda", "Wongjae"); std[2] = new Student("6066260035", "Benjawan", "Punnam"); studentStr[0] = std[0].toString(); studentStr[1] = std[1].toString(); studentStr[2] = std[2].toString(); } public void initSubject() { sub = new SubjectNew[submax]; subjectStr = new String[submax]; sub[0] = new SubjectNew("662305", "IT Laboratory II", 1); sub[1] = new SubjectNew("662309", "Data Structure", 3); sub[2] = new SubjectNew("662310", "Database System", 3); sub[3] = new SubjectNew("662317", "Data Communication", 3); sub[4] = new SubjectNew("662327", "Advanced Computer Programming", 3); subjectStr[0] = sub[0].toString(); subjectStr[1] = sub[1].toString(); subjectStr[2] = sub[2].toString(); subjectStr[3] = sub[3].toString(); subjectStr[4] = sub[4].toString(); } public void initGui() { String line = " "; line += line; container = getContentPane(); container.setLayout(new FlowLayout()); stdLabel = new JLabel("Select Student : "); container.add(stdLabel); stdCombo = new JComboBox(); for(int i=0;i<stdmax;i++) { if(studentStr[i] != null) stdCombo.addItem(studentStr[i]); } stdCombo.setMaximumRowCount(stdmax); container.add(stdCombo); addstdBtn = new JButton("Add Student"); addstdBtn.addActionListener(this); container.add(addstdBtn); stdText = new JTextField(40); stdText.setEditable(false); container.add(stdText); subLabel = new JLabel("Select Subject : "); container.add(subLabel); subCombo = new JComboBox(); for(int i=0;i<submax;i++) { if(subjectStr[i] != null) subCombo.addItem(subjectStr[i]); } subCombo.setMaximumRowCount(submax); container.add(subCombo); addsubBtn = new JButton("Add Subject"); addsubBtn.setEnabled(false); addsubBtn.addActionListener(this); container.add(addsubBtn); subTextArea = new JTextArea(5, 40); subTextArea.setEditable(false); subScroll = new JScrollPane(subTextArea); container.add(subScroll); container.add(new JLabel(" ")); saveBtn = new JButton(" Save "); saveBtn.setEnabled(false); saveBtn.addActionListener(this); container.add(saveBtn); container.add(new JLabel(" ")); cancleBtn = new JButton(" Cancle "); cancleBtn.setEnabled(false); cancleBtn.addActionListener(this); container.add(cancleBtn); container.add(new JLabel(" ")); // ---- Add new subject addsubLabel = new JLabel(" Add new subject"); container.add(addsubLabel); container.add(new JLabel(line)); codeLabel = new JLabel(" Subject Code : "); container.add(codeLabel); codeText = new JTextField(10); container.add(codeText); container.add(new JLabel(" ")); container.add(new JLabel(" ")); nameLabel = new JLabel(" Subject Name : "); container.add(nameLabel); nameText = new JTextField(20); container.add(nameText); container.add(new JLabel(" ")); creditLabel = new JLabel("Subject Credit : "); container.add(creditLabel); creditText = new JTextField(5); container.add(creditText); container.add(new JLabel(" ")); addnewsubBtn = new JButton("Add"); addnewsubBtn.addActionListener(this); container.add(addnewsubBtn); editsubBtn = new JButton("Edit"); editsubBtn.addActionListener(this); container.add(editsubBtn); deletesubBtn = new JButton("Delete"); deletesubBtn.addActionListener(this); container.add(deletesubBtn); clearsubBtn = new JButton("Clear"); clearsubBtn.addActionListener(this); container.add(clearsubBtn); subTextArea2 = new JTextArea(8, 25); subTextArea2.setEditable(false); subScroll2 = new JScrollPane(subTextArea2); container.add(subScroll2); statusText = new JTextField(30); statusText.setEnabled(false); container.add(statusText); // --------- Add new student addstdLabel = new JLabel(" Add new student"); container.add(addstdLabel); container.add(new JLabel(line)); stdcodeLabel = new JLabel(" Student Code : "); container.add(stdcodeLabel); stdcodeText = new JTextField(10); container.add(stdcodeText); container.add(new JLabel(" ")); container.add(new JLabel(" ")); stdnameLabel = new JLabel(" Student Name : "); container.add(stdnameLabel); stdnameText = new JTextField(10); container.add(stdnameText); container.add(new JLabel(" ")); container.add(new JLabel(" ")); stdsurnameLabel = new JLabel("Student Surname : "); container.add(stdsurnameLabel); stdsurnameText = new JTextField(13); container.add(stdsurnameText); container.add(new JLabel(" ")); addnewstdBtn = new JButton("Add"); addnewstdBtn.addActionListener(this); container.add(addnewstdBtn); editstdBtn = new JButton("Edit"); editstdBtn.addActionListener(this); container.add(editstdBtn); deletestdBtn = new JButton("Delete"); deletestdBtn.addActionListener(this); container.add(deletestdBtn); clearstdBtn = new JButton("Clear"); clearstdBtn.addActionListener(this); container.add(clearstdBtn); stdTextArea = new JTextArea(8, 25); stdTextArea.setEditable(false); subScroll2 = new JScrollPane(stdTextArea); container.add(subScroll2); stdstatusText = new JTextField(30); stdstatusText.setEnabled(false); container.add(stdstatusText); } public void actionPerformed(ActionEvent event) { if(event.getSource() == addstdBtn) { int n = stdCombo.getSelectedIndex(); int item = n; while(std[n] == null || std[n].toString().equals(stdCombo.getItemAt(item)) == false) { n++; } stdText.setText(std[n].toString()); reg.setStudent(std[n]); addstdBtn.setEnabled(false); addsubBtn.setEnabled(true); saveBtn.setEnabled(true); cancleBtn.setEnabled(true); } else if(event.getSource() == addsubBtn) { int n = subCombo.getSelectedIndex(); int item = n, credit; while(sub[n] == null || sub[n].toString().equals(subCombo.getItemAt(item)) == false) { n++; } if(count == 0) { credit = sub[n].getSubjectCredit(); if(credit_total + credit > 10) { JOptionPane.showMessageDialog(this, "ลงทะเบียนสูงสุดได้ไม่เกิน 10 หน่วยกิต", "Message", JOptionPane.INFORMATION_MESSAGE); return; } reg.setSubject(sub[n], count); subTextArea.append("[" + (++count) + "] " + sub[n].toString() + " จำนวน " + credit + " หน่วยกิต"); subTextArea.append(" เป็นเงิน " + (credit * 500) + " บาท\n"); credit_total += credit; money_total += credit * 500; saveBtn.setEnabled(true); } else { boolean chk = true; for(int j=0;j<count;j++) { if(sub[n].toString().equals(reg.getSubject(j))) { chk = false; break; } } if(chk) { credit = sub[n].getSubjectCredit(); if(credit_total + credit > 10) { JOptionPane.showMessageDialog(this, "ลงทะเบียนสูงสุดได้ไม่เกิน 10 หน่วยกิต", "Message", JOptionPane.INFORMATION_MESSAGE); return; } reg.setSubject(sub[n], count); subTextArea.append("[" + (++count) + "] " + sub[n].toString() + " จำนวน " + credit + " หน่วยกิต"); subTextArea.append(" เป็นเงิน " + (credit * 500) + " บาท\n"); credit_total += credit; money_total += credit * 500; } } if(count == 5) addsubBtn.setEnabled(false); } else if(event.getSource() == saveBtn) { String output = ""; int credit = 0; output = "นักศึกษา : " + reg.getStudent(); output += "\nวิชาที่ลงทะเบียน\n"; for(int n = 0; n < count; n++) { credit = reg.getSubjectCredit(n); output += "[" + (n+1) + "] " + reg.getSubject(n) + " จำนวน " + credit + " หน่วยกิต"; output += " เป็นเงิน " + (credit * 500) + " บาท\n"; } output += "รวม "+ credit_total + " หน่วยกิต เป็นเงิน " + money_total + " บาท"; JOptionPane.showMessageDialog(this, output, "Registration Data", JOptionPane.INFORMATION_MESSAGE); resetBtn(); } else if(event.getSource() == cancleBtn) { stdText.setText(""); subTextArea.setText(""); count = 0; resetBtn(); } // ------- Subject button else if(event.getSource() == addnewsubBtn) { if(SubjectNew.getCount() == sub.length) { JOptionPane.showMessageDialog(this, "Array full , can not add", "Message", JOptionPane.INFORMATION_MESSAGE); return; } int pos = CheckArrayEmpty(); int n = Integer.parseInt(creditText.getText()); sub[pos] = new SubjectNew(codeText.getText(), nameText.getText(), n); subTextArea2.setText(readString(sub)); JOptionPane.showMessageDialog(this, "Add Subject already", "Message", JOptionPane.INFORMATION_MESSAGE); clearTextField(); updateGui(); } else if(event.getSource() == editsubBtn) { String s = codeText.getText(); int n = searchSubject(sub, s); if(n >= 5 ) { sub[n].setSubjectName(nameText.getText()); sub[n].setSubjectCredit(Integer.parseInt(creditText.getText())); subTextArea2.setText(readString(sub)); JOptionPane.showMessageDialog(this, "Edit Subject already", "Message", JOptionPane.INFORMATION_MESSAGE); clearTextField(); updateGui(); } else if(n >= 0) { JOptionPane.showMessageDialog(this, "Can not edit main subject", "Error Message", JOptionPane.ERROR_MESSAGE); } else { JOptionPane.showMessageDialog(this, "Can not found subject code", "Error Message", JOptionPane.ERROR_MESSAGE); } } else if(event.getSource() == deletesubBtn) { String s = codeText.getText(); int n = searchSubject(sub, s); if(n >= 5) { nameText.setText(sub[n].getSubjectName()); creditText.setText(sub[n].getSubjectCredit() + ""); int ans = JOptionPane.showConfirmDialog(this, "Delete subject", "Confirm", JOptionPane.YES_NO_OPTION); if(ans == 0) { sub[n] = null; subjectStr[n] = null; System.gc(); subTextArea2.setText(readString(sub)); updateGui(); } clearTextField(); } else if(n >= 0) { JOptionPane.showMessageDialog(this, "Can not delete main subject", "Error Message", JOptionPane.ERROR_MESSAGE); } else { JOptionPane.showMessageDialog(this, "Can not found subject code", "Error Messgae", JOptionPane.ERROR_MESSAGE); } } else if(event.getSource() == clearsubBtn) { clearTextField(); } // ------- Student button else if(event.getSource() == addnewstdBtn) { if(Student.getCount() == std.length) { JOptionPane.showMessageDialog(this, "Array full , can not add", "Message", JOptionPane.INFORMATION_MESSAGE); return; } int pos = CheckArrayEmpty2(); std[pos] = new Student(stdcodeText.getText(), stdnameText.getText(), stdsurnameText.getText()); stdTextArea.setText(readString(std)); JOptionPane.showMessageDialog(this, "Add Student already", "Message", JOptionPane.INFORMATION_MESSAGE); clearTextField2(); updateGui2(); } else if(event.getSource() == editstdBtn) { String s = stdcodeText.getText(); int n = searchStudent(std, s); if(n >= 3 ) { std[n].setStudentName(stdnameText.getText()); std[n].setStudentSurName(stdsurnameText.getText()); stdTextArea.setText(readString(std)); JOptionPane.showMessageDialog(this, "Edit Student already", "Message", JOptionPane.INFORMATION_MESSAGE); clearTextField2(); updateGui2(); } else if(n >= 0) { JOptionPane.showMessageDialog(this, "Can not edit main student", "Error Message", JOptionPane.ERROR_MESSAGE); } else { JOptionPane.showMessageDialog(this, "Can not found student code", "Error Message", JOptionPane.ERROR_MESSAGE); } } else if(event.getSource() == deletestdBtn) { String s = stdcodeText.getText(); int n = searchStudent(std, s); if(n >= 3) { stdnameText.setText(std[n].getStudentName()); stdsurnameText.setText(std[n].getStudentSurName()); int ans = JOptionPane.showConfirmDialog(this, "Delete student", "Confirm", JOptionPane.YES_NO_OPTION); if(ans == 0) { std[n] = null; studentStr[n] = null; System.gc(); stdTextArea.setText(readString(std)); updateGui2(); } clearTextField2(); } else if(n >= 0) { JOptionPane.showMessageDialog(this, "Can not delete main student", "Error Message", JOptionPane.ERROR_MESSAGE); } else { JOptionPane.showMessageDialog(this, "Can not found student code", "Error Messgae", JOptionPane.ERROR_MESSAGE); } } else if(event.getSource() == clearstdBtn) { clearTextField2(); } statusText.setText("Number Object : " + SubjectNew.getCount()); stdstatusText.setText("Number Object : " + Student.getCount()); } public void resetBtn() { addstdBtn.setEnabled(true); addsubBtn.setEnabled(false); saveBtn.setEnabled(false); stdText.setText(""); subTextArea.setText(""); count = 0; money_total = 0; credit_total = 0; } public int CheckArrayEmpty() { for(int n = 0; n < sub.length; n++) if(sub[n] == null) return(n); return(-1); } public int CheckArrayEmpty2() { for(int n = 0; n < std.length; n++) if(std[n] == null) return(n); return(-1); } public void clearTextField() { codeText.setText(""); nameText.setText(""); creditText.setText(""); } public void clearTextField2() { stdcodeText.setText(""); stdnameText.setText(""); stdsurnameText.setText(""); } public void updateGui() { for(int i=0;i<sub.length;i++) { if(sub[i] != null) subjectStr[i] = sub[i].toString(); } subCombo.removeAllItems(); for(int i=0;i<submax;i++) { if(subjectStr[i] != null) subCombo.addItem(subjectStr[i]); } } public void updateGui2() { for(int i=0;i<std.length;i++) { if(std[i] != null) studentStr[i] = std[i].toString(); } stdCombo.removeAllItems(); for(int i=0;i<stdmax;i++) { if(studentStr[i] != null) stdCombo.addItem(studentStr[i]); } } public int searchSubject(SubjectNew sub[], String s){ for(int n = 0; n < sub.length; n++) { if(sub[n] != null) if(s.equals(sub[n].getSubjectCode())) return(n); } return(-1); } public int searchStudent(Student std[], String s){ for(int n = 0; n < std.length; n++) { if(std[n] != null) if(s.equals(std[n].getStudentCode())) return(n); } return(-1); } public String readString(SubjectNew sub[]) { String str = ""; for(int n = 0; n < sub.length; n++) { if(sub[n] != null) str += sub[n].toString() + "\n"; } return(str); } public String readString(Student std[]) { String str = ""; for(int n = 0; n < std.length; n++) { if(std[n] != null) str += std[n].toString() + "\n"; } return(str); } public static void main(String[] args) { Lab9_1 lab9_1 = new Lab9_1(); lab9_1.setSize(500, 880); lab9_1.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); lab9_1.setVisible(true); } }
Optional Paste Settings
Category:
None
Cryptocurrency
Cybersecurity
Fixit
Food
Gaming
Haiku
Help
History
Housing
Jokes
Legal
Money
Movies
Music
Pets
Photo
Science
Software
Source Code
Spirit
Sports
Travel
TV
Writing
Tags:
Syntax Highlighting:
None
Bash
C
C#
C++
CSS
HTML
JSON
Java
JavaScript
Lua
Markdown (PRO members only)
Objective C
PHP
Perl
Python
Ruby
Swift
4CS
6502 ACME Cross Assembler
6502 Kick Assembler
6502 TASM/64TASS
ABAP
AIMMS
ALGOL 68
APT Sources
ARM
ASM (NASM)
ASP
ActionScript
ActionScript 3
Ada
Apache Log
AppleScript
Arduino
Asymptote
AutoIt
Autohotkey
Avisynth
Awk
BASCOM AVR
BNF
BOO
Bash
Basic4GL
Batch
BibTeX
Blitz Basic
Blitz3D
BlitzMax
BrainFuck
C
C (WinAPI)
C Intermediate Language
C for Macs
C#
C++
C++ (WinAPI)
C++ (with Qt extensions)
C: Loadrunner
CAD DCL
CAD Lisp
CFDG
CMake
COBOL
CSS
Ceylon
ChaiScript
Chapel
Clojure
Clone C
Clone C++
CoffeeScript
ColdFusion
Cuesheet
D
DCL
DCPU-16
DCS
DIV
DOT
Dart
Delphi
Delphi Prism (Oxygene)
Diff
E
ECMAScript
EPC
Easytrieve
Eiffel
Email
Erlang
Euphoria
F#
FO Language
Falcon
Filemaker
Formula One
Fortran
FreeBasic
FreeSWITCH
GAMBAS
GDB
GDScript
Game Maker
Genero
Genie
GetText
Go
Godot GLSL
Groovy
GwBasic
HQ9 Plus
HTML
HTML 5
Haskell
Haxe
HicEst
IDL
INI file
INTERCAL
IO
ISPF Panel Definition
Icon
Inno Script
J
JCL
JSON
Java
Java 5
JavaScript
Julia
KSP (Kontakt Script)
KiXtart
Kotlin
LDIF
LLVM
LOL Code
LScript
Latex
Liberty BASIC
Linden Scripting
Lisp
Loco Basic
Logtalk
Lotus Formulas
Lotus Script
Lua
M68000 Assembler
MIX Assembler
MK-61/52
MPASM
MXML
MagikSF
Make
MapBasic
Markdown (PRO members only)
MatLab
Mercury
MetaPost
Modula 2
Modula 3
Motorola 68000 HiSoft Dev
MySQL
Nagios
NetRexx
Nginx
Nim
NullSoft Installer
OCaml
OCaml Brief
Oberon 2
Objeck Programming Langua
Objective C
Octave
Open Object Rexx
OpenBSD PACKET FILTER
OpenGL Shading
Openoffice BASIC
Oracle 11
Oracle 8
Oz
PARI/GP
PCRE
PHP
PHP Brief
PL/I
PL/SQL
POV-Ray
ParaSail
Pascal
Pawn
Per
Perl
Perl 6
Phix
Pic 16
Pike
Pixel Bender
PostScript
PostgreSQL
PowerBuilder
PowerShell
ProFTPd
Progress
Prolog
Properties
ProvideX
Puppet
PureBasic
PyCon
Python
Python for S60
QBasic
QML
R
RBScript
REBOL
REG
RPM Spec
Racket
Rails
Rexx
Robots
Roff Manpage
Ruby
Ruby Gnuplot
Rust
SAS
SCL
SPARK
SPARQL
SQF
SQL
SSH Config
Scala
Scheme
Scilab
SdlBasic
Smalltalk
Smarty
StandardML
StoneScript
SuperCollider
Swift
SystemVerilog
T-SQL
TCL
TeXgraph
Tera Term
TypeScript
TypoScript
UPC
Unicon
UnrealScript
Urbi
VB.NET
VBScript
VHDL
VIM
Vala
Vedit
VeriLog
Visual Pro Log
VisualBasic
VisualFoxPro
WHOIS
WhiteSpace
Winbatch
XBasic
XML
XPP
Xojo
Xorg Config
YAML
YARA
Z80 Assembler
ZXBasic
autoconf
jQuery
mIRC
newLISP
q/kdb+
thinBasic
Paste Expiration:
Never
Burn after read
10 Minutes
1 Hour
1 Day
1 Week
2 Weeks
1 Month
6 Months
1 Year
Paste Exposure:
Public
Unlisted
Private
Folder:
(members only)
Password
NEW
Enabled
Disabled
Burn after read
NEW
Paste Name / Title:
Create New Paste
Hello
Guest
Sign Up
or
Login
Sign in with Facebook
Sign in with Twitter
Sign in with Google
You are currently not logged in, this means you can not edit or delete anything you paste.
Sign Up
or
Login
Public Pastes
Energy limiter
4 hours ago | 0.34 KB
GEOMETRY SW
8 hours ago | 1.85 KB
emacs
Lisp | 12 hours ago | 0.69 KB
Obsbot
21 hours ago | 2.51 KB
brain.roblox
1 day ago | 14.59 KB
Untitled
2 days ago | 26.41 KB
Untitled
2 days ago | 14.72 KB
Novagente CLS container
2 days ago | 0.89 KB
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the
Cookies Policy
.
OK, I Understand
Not a member of Pastebin yet?
Sign Up
, it unlocks many cool features!