For Week Lessons Learned and lab reports

Source

 

 

public class NotePad implements ActionListener{


JFrame jframe; // Form
MenuBar menuB; // Menu Bar
Menu menu_Text; // "File" menu
Menu menu_Edit; // "Edit" menu
Menu menu_Help; // "Help" menu
MenuItem text_New; // "New" menu item
MenuItem text_Open; // "open" menu item
MenuItem text_Save; // "Save as" menu item
MenuItem help_Viewhelp; // "View help" menu item
textArea textArea; // text field
FileDialog dia_Open; // "open file" dialog window frame
FileDialog dia_Save; // "save file" dialog window
string str = null; // store text
StringBuffer stringB = new StringBuffer (); // string constant
char [] c; // string into the array
int [] a; ASCII string stored value //

NotePad () {
// create a form
JFrame the JFrame new new = ();
jframe.setTitle ( "Untitled - Notepad"); // Initial title
jframe.setSize (900,600); // Sets the size
jframe.setVisible (true) ; // set the form visible
jframe.setLocationRelativeTo (null); // intermediate form put screen
jframe.setDefaultCloseOperation (JFrame.HIDE_ON_CLOSE); // end process

// Create menu
menuB = new MenuBar (); // create the menu bar
menu_Text = new Menu ( "File"); // Create the "File" menu
menu_Edit = new Menu ( "Edit"); // Create the "Edit" menu
menu_Help = new menu ( "help"); // create the "help" menu
text_New = new MenuItem ( "New"); // create a menu item under the "file" menu
text_Open = new MenuItem ( "open");
text_Save = new MenuItem ( "Save as");
help_Viewhelp = new MenuItem ( "View help");
menu_Text.add (text_New); // add menu items to the menu
menu_Text.add (text_Open);
menu_Text.add (text_Save);
menu_Help.add (help_Viewhelp);
menuB.add (menu_text); // add a menu to the menu bar
menuB.add (menu_Edit);
menuB.add (menu_Help);
jframe.setMenuBar (menuB); // add menu bar to form

//添加监听器
text_New.addActionListener(this);
text_Open.addActionListener(this);
text_Save.addActionListener(this);
help_Viewhelp.addActionListener(this);

// FileDialog (Frame parent, String title , int mode): Creates a file dialog window with the specified title for loading (load) or save (save) files
dia_Open = new FileDialog (jframe, "open file", FileDialog .load);
dia_Save = new new FileDialog (JFrame, "save file", FileDialog.SAVE);


// Create a text field
the textArea the TextArea new new = ();
textArea.setBounds (. 0, 0, jframe.size () width, jframe.size () height.); // Sets the size
textArea.setBackground (Color.white); // set the background color
textArea.setFont (new Font ( "Arial", 0,16)); // new Font (String font, int style, int size), Font.PLAIN or 0: normal font
jframe.add (textArea );
}

// add a click event
@Override
public void actionPerformed (ActionEvent E) {
// TODO Auto-Generated Stub Method,

//e.getSource (): Get click menu item
if (e.getSource () == text_New) {// new
do_new ();
} the else IF (e.getSource () == text_Open) {// Open
do_open ();
} the else IF (e.getSource () == text_Save) {// save
do_sava ();
} the else IF (e.getSource () == help_Viewhelp) {
do_desktop ();
}
}

void do_new () {// new notepad
if (. textArea.getText () equals ( "")) {// determined text field has no content
jframe.setTitle ( "Untitled - Notepad"); // Initial title
the else {}
warning ();
}
}


void do_open () {// Open Notepad
dia_Open.setVisible (true); // dialog boxes
BufferedReader in; // stream object file buffering 
the try {
/ *
* dia_Open.getDirectory (): Get the path of a file
* dia_Open.getFile (): Gets the file name
* getDirectory () + getFile () : the full path to the file
* /
textArea.setText (null); // empty the contents
in = new BufferedReader (new FileReader ( dia_Open.getDirectory () + dia_Open. getFile ())); // select the path
       //in.readLine (): read a whole line (but not including, the newline newline)
       the while ((STR = in.readLine ()) = null) {!
        C = str.toCharArray (); // string into the array
a = new int [str.length () ]; // store strings of ASCII values
for (int i = 0; i <c.length; i ++) {// decrypt
a [i] = (int) c [i] -10; ASCII string stored value //
if (a [i] <0 ) {// If the ASCII value is less than 0, then add 255
a [I] + = 255;
}
c [i] = (char) a [i]; // characters into ASCII value
}
STR = String.valueOf (C); // char into the String
        textArea.append (STR + "\ n-"); // that the end of the string wrap
       }
       in.close (); // Close
       jframe.setTitle (dia_Open.getFile () + "- Notepad"); // open the title display form as: file name + "- Notepad this "
} the catch (IOException E1) {// throws an exception
e1.printStackTrace ();
   }
}

void do_sava () {// Save the Notepad
dia_Save.setVisible (true); // dialog boxes
FileOutputStream out; // file output stream object
the try {
OUT = new new a FileOutputStream (dia_Save.getDirectory () + dia_Save.getFile () + "[encryption] .txt"); // save format of txt file name you entered string 
str = textArea.getText () replace ( " \ n", "\ r \ n");. // Get content text field, and "\ n" replaced "\ R & lt \ n-"   
C = str.toCharArray (); // string to split into an array
a = new int [str.length () ]; // store character string ASCII values
for (int i = 0; i <c.length; i ++) {// encrypt
a [i] = (int) c [i] +10; // characters into ASCII value
if (a [i ]> 255) {// If the ASCII value greater than 255, then subtracting 255
A [I] - = 255;
}
C [I] = (char) A [I]; // values were converted to ASCII characters
}


str = String.valueOf (c); // char into the String
out.write (str.getBytes ()); // str.getBytes (): the string into a byte array   
out.flush (); / / flush the buffer
out.close (); // close
jframe.setTitle (dia_Save.getFile () + "- Notepad"); // save the form will be displayed for a title after: file name + "- Notepad"
} the catch (IOException E1) {
e1.printStackTrace ();
}
}

void do_desktop () {// Open View Help
Desktop desktop = Desktop.getDesktop (); // open the page by default browser
try {// Open the help pages
desktop.browse (new URI ( "https://support.microsoft. COM "));
} the catch (IOException E1) {
// the TODO Auto-Generated Block the catch
e1.printStackTrace ();
} the catch (a URISyntaxException to E1) {
// the TODO Auto-Generated Block the catch
e1.printStackTrace ();
}
}

void warning () {// warning window pops

int option=JOptionPane.showConfirmDialog(null,"是否保存内容?","警告",JOptionPane.YES_NO_OPTION,JOptionPane.WARNING_MESSAGE, null);
switch (option) {
case JOptionPane.YES_NO_OPTION://点击“是” 
  do_sava();
  break;
case JOptionPane.NO_OPTION://点击“否”
textArea.setText(null);
do_new();
  break;
}
}

public static void main(String[] args){
//调用NotePad
new NotePad();
}
}

 

 

 

 

    • 1, JDBC overview
      JDBC provides a platform-independent standard JavaAPI for executing SQL statements, you can easily achieve a unified operating a variety of relational database, which consists of a set of classes and interfaces written in the Java language consisting of
      2. JDBC drivers are divided into four categories:
      . 1) the ODBC-JDBC bridge driver;
      2) JDBA local drive;
      . 3) JDBC network driver;
      4) pure native JDBC driver protocols;
    • Two, MySQL:

      MySQL 是最流行的关系型数据库管理系统,在 WEB 应用方面 MySQL 是最好的 RDBMS(Relational Database Management System:关系数据库管理系统)应用软件之一。

      常用命令:
      show databases; 显示数据库
      create database name; 创建数据库
      use databasename; 选择数据库
      drop database name 直接删除数据库,不提醒

      show tables; 显示表
      describe tablename; 表的详细描述
      select中加上distinct 去除重复字段

Guess you like

Origin www.cnblogs.com/csbtmg/p/11960628.html