⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 21.txt

📁 电子工业出版社出版的《java2应用开发指南》配套光盘源代码
💻 TXT
📖 第 1 页 / 共 5 页
字号:
128     *
129     **/
130     public void displayResults(int p_numRoutes,
131     				 int p_nxtDeptTime) {
132       // Convert the time from int to String format. For ex if the procedure
133       // returns next flight time as 163500 then convert it to 16:35:00 format. 
134       //
135       int l_hh, l_mm, l_ss;
136       l_hh = p_nxtDeptTime / 10000;
137       l_mm = ( p_nxtDeptTime - ( l_hh * 10000) ) / 100;
138       l_ss = ( p_nxtDeptTime - ( l_hh * 10000) - (l_mm * 100) );
139   
140       // Display Number Of Routes
141       m_numRoutesTextfield.setText(String.valueOf(p_numRoutes));
142   
143       // Display Next Departure Time in format 16:35:00
144       if (p_nxtDeptTime == -1) {
145         // If there is no Next Immediate Departure of the Flight
146         m_nxtDepttimeTextfield.setText("");
147         putStatus("No Flight After this time.
148         			 Check from 00:00:00 onwards. ");
149       }else {
150         // Left pad the minute, hour and second variables
151         // with zero if required
152         String l_min = new String(l_mm + "");
153         String l_sec = new String(l_ss + "");
154         String l_hour = new String(l_hh + "");
155         if ((l_hh <= 9) & (l_hh >= 0))  l_hour = "0" + l_hh;
156         if ((l_mm <= 9) & (l_mm >= 0))  l_min = "0" + l_mm;
157         if ((l_ss <= 9) & (l_ss >= 0))  l_sec = "0" + l_ss;
158         // Display Next Departure Time
159         m_nxtDepttimeTextfield.setText(
160         		new String(l_hour+":"+l_min+":"+l_sec ));
161  putStatus("Next Flight Time and Number Of Routes Displayed.");
162       }
163     }
164   
165    /**
166     *  Sets up the listeners that respond to user actions, like 
167     * button press
168     **/
169     public void setupListeners() {
170       // Setup the "CALL PL/SQL PROCEDURE" button listener
171       m_callButton.addActionListener(
172       	new java.awt.event.ActionListener(){
173         public void actionPerformed(ActionEvent e) {
174               clearStatus();
175              putStatus("Calling PL/SQL Stored Procedure.....");
176               // Pass Event to the parent class for handling
177        m_parent.dispatchEvent("CALL PL/SQL STORED PROCEDURE");
178         }
179       });
180   
181       // Setup the "EXIT" button listener
182       m_exitButton.addActionListener(
183       	new java.awt.event.ActionListener(){
184         public void actionPerformed(ActionEvent e) {
185              // Pass Event to the parent class for handling
186               m_parent.dispatchEvent("EXIT");
187         }
188       });
189   
190       // Setup the Combo Box Action listener
191       m_flightCodes.addActionListener(
192       	new java.awt.event.ActionListener(){
193          public void actionPerformed(ActionEvent e) {
194               clearStatus();
195               m_numRoutesTextfield.setText("");
196               m_nxtDepttimeTextfield.setText("");
197               m_depttimeTextfield.setText("");
198          }
199       });
200   
201       // Setup the Departure Time text Fields Action Listener
202       m_depttimeTextfield.addActionListener(
203       	new java.awt.event.ActionListener(){
204        public void actionPerformed(ActionEvent e) {
205               clearStatus();
206               m_numRoutesTextfield.setText("");
207               m_nxtDepttimeTextfield.setText("");
208               m_depttimeTextfield.setText("");
209        }
210       } );
211   
212       // The window exit listener
213       this.addWindowListener(
214       	new java.awt.event.WindowAdapter() {
215         public void windowClosing(WindowEvent e) {
216           m_parent.dispatchEvent("EXIT");
217         }
218       });
219     }
220   
221     /**
222     * Status field message display handlers
223     **/
224         public void clearStatus() {        // Clears status field
225           m_statusField.setText("");
226           m_statusField.setScrollOffset(0);
227          }
228         public void putStatus(String p_status) { 
229         // Puts p_status on status field
230           m_statusField.setText(p_status);
231           m_statusField.setScrollOffset(0);
232         }
233         public void appendStatus(String p_status) { 
234          //Appends p_status to status Field
235           String l_status = m_statusField.getText();
236           m_statusField.setText(l_status+" "+p_status);
237           m_statusField.setScrollOffset(0);
238         }
239   
240     /**
241     * Initialize all the GUI components and the layout
242     **/
243     public void jbInit() throws Exception {
244       this.getContentPane().setLayout(m_gridBagLayout);
245       this.setSize(new Dimension(539, 427));
246       m_flightCodes = new JComboBox();
247      m_flightCodes.setBounds(new Rectangle(272, 49, 153, 30));
248       m_flightCodeLabel.setText("Flight Code");
249       m_flightCodeLabel.setFont(new Font("Dialog", 1, 16));
250       m_callButton.setText("CALL PL/SQL STORED PROCEDURE");
251       m_callButton.setFont(new Font("Dialog", 1, 16));
252       m_exitButton.setText("EXIT");
253       m_exitButton.setFont(new Font("Dialog", 1, 16));
254     m_exitButton.setToolTipText("Press To Exit Application");
255       m_statusField.setBackground(Color.lightGray);
256       m_statusField.setFont(new Font("Monospaced", 0, 12));
257       m_statusField.setDisabledTextColor(Color.lightGray);
258       m_deptTimeLabel.setText("Departure Time");
259       m_deptTimeLabel.setFont(new Font("Dialog", 1, 16));
260       m_depttimeTextfield.setFont(new Font("Dialog", 1, 16));
261       m_numRoutesLabel.setText("Number Of Routes ");
262       m_numRoutesLabel.setFont(new Font("Dialog", 1, 16));
263       m_numRoutesTextfield.setFont(new Font("Dialog", 1, 14));
264       m_numRoutesTextfield.setEditable(false);
265       m_nxtDepttimeLabel.setText("Next Departure Time");
266       m_nxtDepttimeLabel.setFont(new Font("Dialog", 1, 16));
267    m_nxtDepttimeTextfield.setFont(new Font("Dialog", 1, 16));
268       m_nxtDepttimeTextfield.setEditable(false);
269       m_formatLabel.setText("( Format 13:30:00 )");
270       m_formatLabel.setFont(new Font("Dialog", 1, 12));
271 this.setTitle("Accessing PL/SQL Stored Procedure using SQLJ");
272       this.getContentPane().add(m_flightCodeLabel,
273             new GridBagConstraints2(0, 0, 2, 1, 0.0, 0.0,
274             GridBagConstraints.SOUTH,
275             GridBagConstraints.NONE, 
276             new Insets(68, 143, 6, 6), 12, 8));
277       this.getContentPane().add(m_callButton,
278             new GridBagConstraints2(0, 6, 5, 1, 0.0, 0.0,
279             GridBagConstraints.CENTER,
280             GridBagConstraints.NONE, 
281             new Insets(33, 6, 0, 0), 12, 6));
282       this.getContentPane().add(m_exitButton,
283             new GridBagConstraints2(5, 6, 3, 1, 0.0, 0.0,
284             GridBagConstraints.CENTER,
285             GridBagConstraints.NONE, 
286             new Insets(32, 28, 0, 0), 78, 7));
287       this.getContentPane().add(m_statusField,
288             new GridBagConstraints2(0, 7, 9, 1, 1.0, 1.0 ,
289             GridBagConstraints.CENTER,
290             GridBagConstraints.BOTH, 
291             new Insets(11, -2, -2, -1), 529, 55));
292       this.getContentPane().add(m_deptTimeLabel,
293             new GridBagConstraints2(0, 1, 3, 1, 0.0, 0.0,
294             GridBagConstraints.SOUTHEAST,
295             GridBagConstraints.NONE, 
296             new Insets(16, 130, 6, 2), 14, 13));
297       this.getContentPane().add(m_depttimeTextfield,
298             new GridBagConstraints2(4, 1, 2, 1, 1.0, 0.0 ,
299             GridBagConstraints.NORTHWEST,
300             GridBagConstraints.HORIZONTAL, 
301             new Insets(13, 21, 8, 28), 149, 10));
302       this.getContentPane().add(m_numRoutesLabel,
303             new GridBagConstraints2(0, 5, 4, 1, 0.0, 0.0,
304             GridBagConstraints.CENTER,
305             GridBagConstraints.NONE, 
306             new Insets(21, 104, 7, 5), 14, 12));
307       this.getContentPane().add(m_numRoutesTextfield,
308             new GridBagConstraints2(4, 5, 3, 1, 1.0, 0.0 ,
309             GridBagConstraints.WEST,
310             GridBagConstraints.BOTH,
311             new Insets(27, 21, 0, 26), 151, 14));
312       this.getContentPane().add(m_nxtDepttimeLabel,
313             new GridBagConstraints2(0, 3, 2, 1, 0.0, 0.0,
314             GridBagConstraints.WEST,
315             GridBagConstraints.NONE, 
316             new Insets(13, 93, 0, 0), 4, 8));
317       this.getContentPane().add(m_nxtDepttimeTextfield,
318             new GridBagConstraints2(4, 3, 2, 2, 1.0, 0.0 ,
319             GridBagConstraints.WEST,
320             GridBagConstraints.HORIZONTAL, 
321             new Insets(8, 21, 0, 26), 150, 11));
322       this.getContentPane().add(m_formatLabel,
323             new GridBagConstraints2(0, 1, 1, 2, 0.0, 0.0,
324             GridBagConstraints.WEST,
325             GridBagConstraints.NONE, 
326             new Insets(49, 138, 0, 0), 0, 9));
327     }
328   }
例程21-7
1    /**
2     * @author  Ashok S
3     * @version 1.0
4     *
5     * Development Environment        :  JDeveloper 2.0
6     * Name of the Application        :  gridBagConstraints2.java
7     * Creation/Modification History  :
8     *
9     *    ashivaru.in       24-Dec-1998      Created
10    *
11    * Overview of Application        :
12    *
13    * An easy way to use GridBagConstraints. Avoids multiple method 
14    * calls of GridBagConstraint methods
15    */
16   import java.awt.*;
17   
18   public class GridBagConstraints2
19   extends GridBagConstraints
20   {
21   
22   	/**
23   	*	Constructor. Initializes GridBagConstraints variables.
24   	*	@param	gx	gridx
25   	*	@param	gy	gridy	
26   	*	@param	gw	gridwidth
27   	*	@param 	gh	gridheight
28   	*	@param	wx	widthx
29   	*	@param	wy	widthy
30   	*	@param	anc	anchor
31   	*	@param	fil	fill
32   	*	@param	ins	Insets
33   	*	@see	java.awt.Insets
34   	*	@param	ix	ipadx
35   	*	@param	iy	ipady
36   	*
37   	**/
38   	public GridBagConstraints2(int gx, int gy, int gw, int gh,
39   			double wx, double wy, int anc, int fil, Insets ins, 
40   			int ix, int iy) {
41   		gridx = gx;
42   		gridy = gy;
43   		gridwidth = gw;
44   		gridheight = gh;
45   
46   		weightx = wx;
47   		weighty = wy;
48   
49   		anchor = anc;
50   		fill = fil;
51   		
52   		insets = ins;
53   		ipadx = ix;
54   		ipady = iy;
55   
56   	}
57   }
例程21-8
1    /**
2     * @author  Srinivasa Rangan
3     * @version 1.0
4     *
5     * Development Environment        :  JDeveloper 2.0
6     * Name of the Application        :  ConnectionParams.java
7     * Creation/Modification History  :
8     *
9     *    srangan.in       15-Feb-1998      Created
10    *
11    * Overview of Application        :
12    *
13    * Contains static variables which define the connection 
14    * parameters for the database to which the samples connect.
15    *
16    * Please substitute the parameters with the values for your 
17    * database.
18    */
19   
20    public class ConnectionParams {
21   
22      // The machine on which the database resides
23      public final static String s_hostName     = "localhost";
24   
25      // The TNS listener port
26      public final static String s_portNumber   = "1521";
27   
28      // The database name (SID)
29      public final static String s_databaseSID = "quest803";
30   
31      // The database User ID
32      public final static String s_userName = "scott";
33   
34      // The database user password
35      public final static String s_password     = "tiger";
36   
37    }
例程21-9
1    Rem
2    Rem  Copyright (C) By Oracle Corporation 1998
3    Rem  
4    Rem  Name  : plsqlSample.sql
5    Rem
6    Rem  Functionality :
7    Rem
8    Rem  This Script Creates a PL/SQL Stored Procedure namely 
9    Rem  nxt_flight_time_and_num_routes       
10   Rem  The parameters passed to this Stored Procedure are
11   Rem   a) flight_code which is IN parameter.
12   Rem   b) Flight_time which is In OUT parameter
13   Rem   c) how_many_routes which is OUT parameter.
14   Rem
15   Rem  How to run this Script :
16   Rem    Use svrmgrl and connect to proper database
17   Rem    For Example connect to insn110a 
18   Rem    svrmgrl
19   Rem    SQL> @plsqlSample.sql
20   Rem
21   Rem  Modification/Creation History
22   Rem
23   Rem       ukulkarn.in      Creation   24-Dec-1998
24   Rem
25   
26   
27   CREATE OR REPLACE PROCEDURE nxt_flight_time_and_num_routes(
28   				flight_Code in VARCHAr2, 
29   				Flight_time IN OUT NUMBER,
30   				 how_many_routes OUT NUMBER)
31   IS
32     tmp_flight_time NUMBER;
33   BEGIN
34     SELECT COUNT(ROUTE_ID)
35     INTO how_many_routes
36     FROM FLIGHT_ROUTES
37     WHERE FLIGHT_NUMBER = TO_NUMBER(FLIGHT_CODE);
38   
39     SELECT min(DEPARTURE_TIME)
40     INTO tmp_flight_time
41     FROM FLIGHT_DEPARTURES
42     WHERE DEPARTURE_TIME > FLIGHT_TIME and ID = FLIGHT_CODE  
43     GROUP BY ID;
44   
45   
46     flight_time := tmp_flight_time;
47   EXCEPTION
48     WHEN NO_DATA_FOUND THEN
49         flight_time := -1;
50   END;
51   /
52   show errors


例程21-10
1     import java.io.*;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -