VERİTABANI YAPISI
CREATE TABLE student (
student_id int(5) NOT NULL auto_increment,
student_number int(5) NOT NULL default '0',
student_firstname varchar(32) NOT NULL default '',
student_lastname varchar(32) NOT NULL default '',
student_department_id int(5) NOT NULL default '0',
PRIMARY KEY (student_id)
) TYPE=MyISAM;
INSERT INTO student VALUES (1, 111, 'Baris', 'Efe', 1);
INSERT INTO student VALUES (2, 222, 'Ali', 'Aksel', 1);
CREATE TABLE student_announcement (
student_announcement_id int(5) NOT NULL auto_increment,
student_announcement_text varchar(255) NOT NULL default '',
PRIMARY KEY (student_announcement_id)
) TYPE=MyISAM;
INSERT INTO student_announcement VALUES (1, 'Finaller Ocak ayinin 2 haftasina ertelendi.');
INSERT INTO student_announcement VALUES (2, 'Ogrenci kimlikleri dagitilmaya baslandi.');
CREATE TABLE student_course (
student_course_id int(5) NOT NULL auto_increment,
student_course_name varchar(255) NOT NULL default '',
PRIMARY KEY (student_course_id)
) TYPE=MyISAM;
INSERT INTO student_course VALUES (1, 'Java');
INSERT INTO student_course VALUES (2, 'SQL');
INSERT INTO student_course VALUES (3, 'C');
CREATE TABLE student_department (
student_department_id int(5) NOT NULL auto_increment,
student_department_name varchar(100) NOT NULL default '',
PRIMARY KEY (student_department_id)
) TYPE=MyISAM;
INSERT INTO student_department VALUES (1, 'EST');
CREATE TABLE student_news (
student_news_id int(5) NOT NULL auto_increment,
student_news_text varchar(255) NOT NULL default '',
PRIMARY KEY (student_news_id)
) TYPE=MyISAM;
INSERT INTO student_news VALUES (1, 'Rektorun konusmasi 3 Ocak 2003 14:00 te Fen Fakultesinde');
INSERT INTO student_news VALUES (2, 'Kutuphaneye yeni Java kitaplari alindi.');
INSERT INTO student_news VALUES (3, 'Maslak kampusunde yeni kantin aciliyor.');
CREATE TABLE student_score (
student_score_id int(5) NOT NULL auto_increment,
student_number int(5) NOT NULL default '0',
student_course int(5) NOT NULL default '0',
student_score varchar(255) NOT NULL default '',
PRIMARY KEY (student_score_id)
) TYPE=MyISAM;
INSERT INTO student_score VALUES (1, 111, 1, '67');
INSERT INTO student_score VALUES (2, 111, 2, '87');
INSERT INTO student_score VALUES (3, 111, 3, '34');
INSERT INTO student_score VALUES (4, 222, 2, '97');
INSERT INTO student_score VALUES (5, 222, 3, '48');
MIDLETLER MIDletler bir ana nesne, duruma göre değişen ekranlar için tasarlanmış nesneler ve ağ bağlantısını sağlayan nesneden meydana geliyor. MIDletlerin kaynak kodları:
1 / * *
2 * Student. java
3 * @author Baris Efe
4 * @version 1. 0
5 * /
6 package studentlet;
7 import java. io. * ;
8 import javax. microedition. io. * ;
9 import javax. microedition. lcdui. * ;
10 import javax. microedition. midlet. * ;
11 public class Student extends MIDlet implements CommandListener {
12 private static Student instance;
13 private InfoScreen scrInfoScreen;
14 private StudentNumberScreen scrStudentNumberScreen;
15 private WaitCanvas scrWait;
16 private Command cancelCommand ;
17 private HttpWorker httpWorker;
18 public String studentNumber;
19 private static String url = "http:/ / localhost:8080/ student";
20 / * * Constructor * /
21 public Student( ) {
22 instance = this ;
23 }
24 / * * Main method * /
25 public void startApp( ) {
26 Displayable current=Display. getDisplay( this ) . getCurrent( ) ;
27 if ( current==null ) {
28 scrInfoScreen = new InfoScreen( this ) ;
29 scrStudentNumberScreen = new StudentNumberScreen( this ) ;
30 Display. getDisplay( this ) . setCurrent( scrStudentNumberScreen) ;
31 scrWait = new WaitCanvas( ) ;
32 cancelCommand = new Command( "Iptal", Command. CANCEL, 0) ;
33 scrWait. addCommand( cancelCommand) ;
34 scrWait. setCommandListener( this ) ;
35 httpWorker = new HttpWorker( this , scrWait, url) ;
36 httpWorker. start( ) ;
37 } else {
38 Display. getDisplay( this ) . setCurrent( current) ;
39 }
40 }
41 / * * Handle pausing the MIDlet * /
42 public void pauseApp( ) {
43 }
44 / * * Handle destroying the MIDlet * /
45 public void destroyApp( boolean unconditional) {
46 }
47 / * * Quit the MIDlet * /
48 public static void quitApp( ) {
49 instance. destroyApp( true ) ;
50 instance. notifyDestroyed( ) ;
51 instance = null ;
52 }
53 public void networkResponse( String s) {
54 / / System. out. println( "debug, Student. networkResponse( ) , "+ s) ;
55 if ( s. compareTo( "false ") ==0) {
56 scrStudentNumberScreen. setResultText( "Ogrenci numarasi bulunamadi. Lutfen tekrar deneyiniz. ") ;
57 this . studentNumber="";
58 Display. getDisplay( this ) . setCurrent( scrStudentNumberScreen) ;
59 } else {
60 scrInfoScreen. setResultText( s) ;
61 Display. getDisplay( this ) . setCurrent( scrInfoScreen) ;
62 }
63 }
64 public void runHttpWorker( String queryString) {
65 httpWorker. setQueryString( queryString) ;
66 httpWorker. go( ) ;
67 }
68 public void showWaitScreen( ) {
69 scrWait. setMessage( "Baglaniyor. . . ") ;
70 Display. getDisplay( this ) . setCurrent( scrWait) ;
71 }
72 public void showStudentNumberScreen( ) {
73 Display. getDisplay( this ) . setCurrent( scrStudentNumberScreen) ;
74 }
75 public void commandAction( Command c, Displayable s) {
76 if ( c == cancelCommand) {
77 Display. getDisplay( this ) . setCurrent( scrInfoScreen) ;
78 httpWorker. cancel( ) ;
79 }
80 }
81 }
1 / * *
2 * StudentNumberScreen. java
3 * @author Baris Efe
4 * @version 1. 0
5 * /
6 package studentlet;
7 import java. io. * ;
8 import javax. microedition. io. * ;
9 import javax. microedition. lcdui. * ;
10 import javax. microedition. midlet. * ;
11 public class StudentNumberScreen extends Form implements CommandListener{
12 private Student midlet;
13 private StringItem txtResultText;
14 private TextField txtStudentNumber;
15 public StudentNumberScreen( Student midlet) {
16 super ( "Ogrenci Bilgi") ;
17 this . midlet=midlet;
18 try {
19 txtStudentNumber = new TextField( "Ogrenci Numarasi:", "", 10, 0) ;
20 txtResultText = new StringItem( "", "") ;
21 setCommandListener( this ) ;
22 addCommand( new Command( "Gonder", Command. OK, 1) ) ;
23 this . append( txtStudentNumber) ;
24 this . append( txtResultText) ;
25 }
26 catch ( Exception e) {
27 e. printStackTrace( ) ;
28 }
29 }
30 public void setResultText( String httpResponseText) {
31 txtResultText. setText( httpResponseText) ;
32 }
33 public void commandAction( Command command, Displayable displayable) {
34 if ( command. getCommandType( ) == Command. OK) {
35 midlet. studentNumber = txtStudentNumber. getString( ) ;
36 midlet. showWaitScreen( ) ;
37 midlet. runHttpWorker( "action=getStudentNumber&studentNumber="+ txtStudentNumber. getString( ) ) ;
38 }
39 }
40 }
1 / * *
2 * InfoScreen. java
3 * @author Baris Efe
4 * @version 1. 0
5 * /
6 package studentlet;
7 import java. io. * ;
8 import javax. microedition. io. * ;
9 import javax. microedition. lcdui. * ;
10 import javax. microedition. midlet. * ;
11 public class InfoScreen extends Form implements CommandListener{
12 private Student midlet;
13 private StringItem txtResultText;
14 public InfoScreen( Student midlet) {
15 super ( "Ogrenci Bilgi") ;
16 this . midlet=midlet;
17 try {
18 txtResultText = new StringItem( "", "") ;
19 setCommandListener( this ) ;
20 addCommand( new Command( "Duyuru? ", Command. SCREEN, 1) ) ;
21 addCommand( new Command( "Haber? ", Command. SCREEN, 1) ) ;
22 addCommand( new Command( "Not? ", Command. SCREEN, 1) ) ;
23 addCommand( new Command( "Numara? ", Command. SCREEN, 1) ) ;
24 addCommand( new Command( "Cikis", Command. SCREEN, 1) ) ;
25 this . append( txtResultText) ;
26 }
27 catch ( Exception e) {
28 e. printStackTrace( ) ;
29 }
30 }
31 public void setResultText( String httpResponseText) {
32 txtResultText. setText( httpResponseText) ;
33 }
34 public void commandAction( Command command, Displayable displayable) {
35 if ( command. getCommandType( ) == Command. OK) {
36 midlet. showWaitScreen( ) ;
37 midlet. runHttpWorker( "action=test") ;
38 } else if ( command. getCommandType( ) == Command. SCREEN) {
39 String commandName = command. getLabel( ) ;
40 System. out. println( "commandName:"+ commandName) ;
41 if ( commandName. equals( "Duyuru? ") ) {
42 midlet. showWaitScreen( ) ;
43 midlet. runHttpWorker( "action=announcement") ;
44 } else if ( commandName. equals( "Haber? ") ) {
45 midlet. showWaitScreen( ) ;
46 midlet. runHttpWorker( "action=news") ;
47 } else if ( commandName. equals( "Not? ") ) {
48 midlet. showWaitScreen( ) ;
49 midlet. runHttpWorker( "action=scores&studentNumber="+ midlet. studentNumber) ;
50 } else if ( commandName. equals( "Numara? ") ) {
51 midlet. showStudentNumberScreen( ) ;
52 } else if ( commandName. equals( "Cikis") ) {
53 midlet. quitApp( ) ;
54 }
55 }
56 }
57 }
1 / * *
2 * WaitCanvas. java
3 * @author Baris Efe
4 * @version 1. 0
5 * /
6 package studentlet;
7 import java. util. * ;
8 import java. io. * ;
9 import javax. microedition. io. * ;
10 import javax. microedition. lcdui. * ;
11 public class WaitCanvas extends Canvas {
12 private int mCount, mMaximum;
13 private int mInterval;
14 private int mWidth, mHeight, mX, mY, mRadius;
15 private String mMessage="Studentlet. . . ";
16 public WaitCanvas( ) {
17 mCount = 0;
18 mMaximum = 36;
19 mInterval = 100;
20 mWidth = getWidth( ) ;
21 mHeight = getHeight( ) ;
22 / / Calculate the radius.
23 int halfWidth = ( mWidth - mRadius) / 2;
24 int halfHeight = ( mHeight - mRadius) / 2;
25 mRadius = Math. min( halfWidth, halfHeight) ;
26 / / Calculate the location.
27 mX = halfWidth - mRadius / 2;
28 mY = halfHeight - mRadius / 2;
29 / / Create a Timer to update the display.
30 TimerTask task = new TimerTask( ) {
31 public void run( ) {
32 mCount = ( mCount + 1) % mMaximum;
33 repaint( ) ;
34 }
35 } ;
36 Timer timer = new Timer( ) ;
37 timer. schedule( task, 0, mInterval) ;
38 }
39 public void setMessage( String s) {
40 mMessage = s;
41 repaint( ) ;
42 }
43 public void paint( Graphics g) {
44 int theta = - ( mCount * 360 / mMaximum) ;
45 / / Clear the whole screen.
46 g. setColor( 255, 255, 255) ;
47 g. fillRect( 0, 0, mWidth, mHeight) ;
48 / / Now draw the pinwheel.
49 g. setColor( 0, 0, 0) ;
50 g. drawArc( mX, mY, mRadius, mRadius, 0, 360) ;
51 g. fillArc( mX, mY, mRadius, mRadius, theta + 90, 90) ;
52 g. fillArc( mX, mY, mRadius, mRadius, theta + 270, 90) ;
53 / / Draw the message, if there is a message.
54 if ( mMessage ! = null )
55 g. drawString( mMessage, mWidth / 2, mHeight,
56 Graphics. BOTTOM | Graphics. HCENTER) ;
57 }
58 }
1 / * *
2 * HttpWorker. java
3 * @author Baris Efe
4 * @version 1. 0
5 * /
6 package studentlet;
7 import java. io. * ;
8 import javax. microedition. io. * ;
9 import javax. microedition. lcdui. * ;
10 public class HttpWorker extends Thread {
11 private Student midlet;
12 private WaitCanvas scrWait;
13 private String url;
14 private HttpConnection httpConnection;
15 private boolean mTrucking, mCancel;
16 private String queryString = null ;
17 public HttpWorker( Student midlet, WaitCanvas waitCanvas, String url) {
18 this . midlet=midlet;
19 scrWait = waitCanvas;
20 this . url = url;
21 mTrucking = true ;
22 mCancel = false ;
23 }
24 public synchronized void run( ) {
25 while ( mTrucking) {
26 try { wait( ) ; }
27 catch ( InterruptedException ie) { }
28 if ( mTrucking) connect( ) ;
0 yorum yazılmıştır