Java大学实用教程 Hello.java class A { void f() { System.out.println("I am A"); } } class B { } public class Hello { public static void main (String args[ ]) { System.out.println("你好,很高兴学习Java"); A a=new A(); a.f(); } } Tom.java public class Tom{ int leg; String head; void cry(String s){ System.out.println(s); } } class Example{ public static void main(String args[]) { Tom cat; cat=new Tom(); cat.leg=4; cat.head="猫头"; System.out.println("腿:"+cat.leg+"条"); System.out.println("头:"+cat.head); cat.cry("我今天要和Jerry拼了"); } } Ch10 importjavax.swing.*; importjava.awt.event.InputEvent; importjava.awt.event.KeyEvent; public class Example10_1{ public static void main(String args[]){ FirstWindow win=new FirstWindow("一个简单的窗口"); } } classFirstWindow extends JFrame{ JMenuBarmenubar; JMenu menu; JMenuItem item1,item2; FirstWindow(String s){ setTitle(s); setSize(160,170); setLocation(120,120); setVisible(true); menubar=new JMenuBar(); menu=new JMenu("文件"); item1=new JMenuItem("打开",new ImageIcon("open.gif")); item2=new JMenuItem("保存",new ImageIcon("save.gif")); item1.setAccelerator(KeyStroke.getKeyStroke('O')); item2.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S,InputEvent.CTRL_MASK)); menu.add(item1); menu.addSeparator(); menu.add(item2); menubar.add(menu); setJMenuBar(menubar); validate(); setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); } } 完全版:Java大学实用教程(第2版)[程序源代码].zip 本文来源:https://www.wddqw.com/doc/0b4a437301f69e3143329455.html