(Java) Swing
(Java) http://www.swust.net.cn
AWTSWING JavaAWT(Abstract Windows Toolkit) AWT (WindowsMacintoshLinux)GUI(Peers) PeersGUIAWTPeerspeers
(Java) http://www.swust.net.cn
(AWT) (Swing)
(Java) http://www.swust.net.cn
AWTSwingAWT Swing bug swing SwingAWT
(Java) http://www.swust.net.cn
JComponentJFrameJDialogjavax.swingJComponentjava.awtContainerComponenetjavax.swingJFameJDialogjava.awtFrameDialogWindow
(Java) http://www.swust.net.cn
(component)JavaComponent (container) JavaContainer
(Java) http://www.swust.net.cn
add( ) removeAll() remove(Component c) validate()
(Java) http://www.swust.net.cn
()
(Java) http://www.swust.net.cn
Swing SwingMVC( - - ) MVCGUI () ()
(Java) http://www.swust.net.cn
(Java) http://www.swust.net.cn
(JButton) javax.swing25050(J) javax.swing JAppletJFrameJDialogJComponent JFrameJAppletJDialog swingJava(Java Foundation ClassesJFC)
(Java) http://www.swust.net.cn
JFrame JFrame JFrame JFrame JFame JFameJFame JFamegetContentPane()
(Java) http://www.swust.net.cn
(Java) http://www.swust.net.cn
JFrame JFrame() : JFrame(String s) :s public void setBounds(int a,int b,int width,int height) (a,b)abwidthheight
(Java) http://www.swust.net.cn
public void setSize(int width,int height)(0,0) public void setVisible(boolean b) public void setResizable(boolean b)
(Java) http://www.swust.net.cn
public void setDefaultCloseOperation(int operation) : operation DO_NOTHING_ON_CLOSE HIDE_ON_CLOSE DISPOSE_ON_CLOSE EXIT_ON_CLOSE
(Java) http://www.swust.net.cn
Swing(JMenuBar)(JMenu)(JMenuItem) () JMenuBar JMenuBarJComponent JMenuBar menuBar=new JMenuBar(); JFrame public void setJMenuBar(JMenuBar menubar);
(Java) http://www.swust.net.cn
JMenu JMenuJComponent pulbic JMenu() pulbic JMenu(String s)s Edit JMenu editMenu=new JMenu(Edit); menuBar.add(editMenu);
(Java) http://www.swust.net.cn
public void add(MenuItem item)item public void add(String s) public JMenuItem getItem(int n) public int getItemCount()
(Java) http://www.swust.net.cn
JMenuItem JMenuJComponent public JMenuItem(String s) public JMenuItem(String text, Icon icon) Icon icon=new ImageIcon(); JMenuItem pasteItem=new JMenuItem(Paste); editMenu.add(pasteItem);
(Java) http://www.swust.net.cn
public void setEnabled(boolean b) public String getLabel(): public void setAccelerator(KeyStroke keystroke): public static KeyStroke getKeyStroke(int keyCode, int modifiers) :KeyStrokekeyCode KeyEvent.VK_A~ KeyEvent.VK_Z modifiersInputEvent.ALT_MASK InputEvent .CTRL_MASK InputEvent .SHIFT_MASK
(Java) http://www.swust.net.cn
JMenu JMenu editMenu = new JMenu(Edit);JMenu optionsMenu = new JMenu(Options);editMenu.add(optionsMenu);
(Java) http://www.swust.net.cn
: ,
(Java) http://www.swust.net.cn
AWT FlowLayout BoderLayout CardLayout GridLayout BoxLayout setLayout()
(Java) http://www.swust.net.cn
BorderLayoutWindowJframeJDialogBorderLayout(EAST) ,(SOUTH),(WEST),(NORTH),(CENTER)0CENTER
(Java) http://www.swust.net.cn
BorderLayout()0BorderLayout BorderLayout(int hgap,int vgap)BorderLayout BorderLayoutadd() add(,)
(Java) http://www.swust.net.cn
import java.awt.*;import javax.swing.*;public class BorderL{ public static void main(String[ ] args){ JFrame f; JButton be,bw,bn,bs,bc; BorderL that=new BorderL(); f=new JFrame("); be=new JButton(); bs=new JButton("); bw=new JButton(); bn=new JButton("); bc=new JButton("); f.getContentPane().add(be,"East"); f.getContentPane().add(bs,"South"); f.getContentPane().add(bw,"West"); f.getContentPane().add(bn,"North"); f.getContentPane().add(bc,"Center"); f.setSize(350,200);f.setVisible(true); } }
(Java) http://www.swust.net.cn
FlowLayoutFlowLayout()FlowLayout(int align)FlowLayout(int align,int hgap,int vgap)FlowLayout.LEFT, FlowLayout.RIGHT,FlowLayout.CENTERhgap:vgap5
(Java) http://www.swust.net.cn
FlowLayout getPreferredSize() FlowLayoutJPanle
(Java) http://www.swust.net.cn
(Java) http://www.swust.net.cn
GridLayout:GridLayout():GridLayout(int rows,int cols)rowscols0GridLayout(int rows,int cols,int hgap,int vgap)
(Java) http://www.swust.net.cn
GridLayout GridLayout GridLayoutadd GridLayout
(Java) http://www.swust.net.cn
CardLayout(JTabbedPane)CardLayoutJTabbedPaneadd(String text,Component c);ctext
(Java) http://www.swust.net.cn
BoxLayout BoxLayout Box BoxcreateHorizontalBox() BoxcreateHorizontalStrut(int width)Struct
(Java) http://www.swust.net.cn
BoxcreateVerticalBox() BoxcreateVertialStrut(int height)Struct
(Java) http://www.swust.net.cn
JPanel JPanel(add) JPanelFlowLayout JPanel()
(Java) http://www.swust.net.cn
JScrollPane JTextArea JScrollPane(component c)
(Java) http://www.swust.net.cn
JSplitPane JSplitPane(int a, Component b ,Component c) setDividerLocation(double position)
(Java) http://www.swust.net.cn
JLayeredPane JLayeredPane JLayeredPane5add(Jcomponent com, int layer); comcom layer DEFAULT_LAYER PALETTE_LAYER MODAL_LAYER POPUP_LAYER DRAG_LAYER
(Java) http://www.swust.net.cn
public void setLayer(Component c,int layer)c public int getLayer(Component c)c
(Java) http://www.swust.net.cn
JTextField JTextField(int x)x JTextField(String s) s
(Java) http://www.swust.net.cn
public void setText(String s)s public String getText() public void setEditable(boolean b) () public void setHorizontalAlignment(int alignment) alignmentLEFTCENTERRIGHT
(Java) http://www.swust.net.cn
JPasswordField setEchoChar(char c)* char[ ] getPassword()
(Java) http://www.swust.net.cn
ActionEvent (source,) (Event Listener)() addxxxListener(Event Listener)
(Java) http://www.swust.net.cn
java.awt.event ()EA()AE
(Java) http://www.swust.net.cn
(Java) http://www.swust.net.cn
(Java) http://www.swust.net.cn
java.utilEventObjectEventListener java.awt.event(Adapter)
(Java) http://www.swust.net.cn
ActionEvent addActionListener(ActioListener listener); ActionListener public void actionPerformed(ActionEvent e)class MyListener extends ActionListener{ . Mylistener listener = new Mylistener();.addActionListener(listener); . public void actionPerformed(ActionEvent e){ // }}
(Java) http://www.swust.net.cn
.addActionListener( new ActionListener(){ . public void actionPerformed(ActionEvent e){ // }); public Object getSource()ActionEvent
(Java) http://www.swust.net.cn
JTextArea JTextArea JTextArea(int rows, int columns)rowscolumns setLineWrap(boolean b) setWrapStyleWord(boolean b)(btrue)(bfalse)
(Java) http://www.swust.net.cn
getText() setText(String s) : append(String s) insert(String s,int x) public void copy() public void cut() public void paste()JTextComponent
(Java) http://www.swust.net.cn
JButton : JButton(String text)text public JButton(Icon icon)icon public JButton(String text, Icon icon)texticon
(Java) http://www.swust.net.cn
public String getText(): public void setText(String text)text public Icon getIcon(): public void setIcon(Icon icon): public void setHorizontalTextPosition(int textPosition):SwingConstants.RIGHT SwingConstants.LEFT SwingConstants.CENTER SwingConstants.LEADING SwingConstants.TRAILING
(Java) http://www.swust.net.cn
public void setVerticalTextPosition(int textPosition) public void addActionListener(ActionListener) public void removeActionListener(ActionListener)
(Java) http://www.swust.net.cn
JLabel JLabel public JLabel () public JLabel (String s ) public JLabel(String s, int aligment) public JLabel (Icon icon) public JLabel (String s,Icon icon,int aligment)SwingConstants.RIGHT SwingConstants.LEFT SwingConstants.CENTER SwingConstants.LEADING SwingConstants.TRAILING
(Java) http://www.swust.net.cn
String getText() void setText(String s) Icon getIcon() void setIcon(Icon icon) void setHorizontalTextPosition(int a) aa JLabel.LEFTJLabel.RIGHT void setVerticalTextPosition(int a) aJLabelaJLabel.BOTTOMJLabel.TOP
(Java) http://www.swust.net.cn
JCheckBox public JCheckBox()public JCheckBox(String text)textpublic JCheckBox(Icon icon)iconpublic JCheckBox(String text, Icon icon)text
(Java) http://www.swust.net.cn
public void setIcon(Icon defaultIcon) public void setSelectedIcon(Icon selectedIcon) public boolean isSelected() truefalse ,
(Java) http://www.swust.net.cn
ItemEvent addItemListener(ItemListener listener):ItemEvent public void itemStateChanged(ItemEvent e): getItemSelectable():Itemevent class CheckBoxWindow extends JFrame implements ItemListener { box.addItemListener(this); public void itemStateChanged(ItemEvent e) {//}}
(Java) http://www.swust.net.cn
JRadioButton ButtonGroup ButtonGroup grounp=new ButtonGroup();JRadioButton button1=new JRadioButton(); button2=new JRadioButton(); grounp.add(button1); grounp.add(button2);
(Java) http://www.swust.net.cn
public JComboBox() public void addItem(Object anObject) public int getSelectedIndex() 0
(Java) http://www.swust.net.cn
public Object getSelectedItem() public void removeItemAt(int anIndex) anIndex public void removeAllItems() public void addItemListener(ItemListener) ItemEventItemEventItemEvent
(Java) http://www.swust.net.cn
JTable JTable (Object[ ][ ] data , Object[ ] columnName)datacolumnNameObjectdataObject[][] a = new Object[3][4];Object[] name = {"","","",""};JTable table=new JTable(a,name);
(Java) http://www.swust.net.cn
JTree MutableTreeNode
(Java) http://www.swust.net.cn
DefaultMutableTreeNode MutableTreeNode DefaultMutableTreeNode(Object userObject): DefaultMutableTreeNode(Object userObject,boolean allowChildren):allowChildrentrue
(Java) http://www.swust.net.cn
TreeSelectionEventaddTreeSelectionListener(TreeSelectionListener listener)TreeSelectionEventpublic void valueChanged (TreeSelection Event e)TreeSelectionEventgetLastSelectedPathComponent() getUserObject()
(Java) http://www.swust.net.cn
JProgressBarJProgressBarJProgessBar()JProgressBar(int min,int max) JProgressBar(int orient ,int min,int max) pulic void set setValue(int n) setMinimum(int min) setMaximum(int max)
(Java) http://www.swust.net.cn
ProgressMonitorInputStreamjavax.swing ProgressMonitorInputStreamConmponent c,String s,InputStream);
(Java) http://www.swust.net.cn
JComponent (0,0)2010x20y10
(Java) http://www.swust.net.cn
public void setBackground(Color c) : public void setForeground(Color c): public Color getBackground(Color c): public Color getForeground(Color c) : public Color(int red,int green,ing blue):redgreenblue0255
(Java) http://www.swust.net.cn
public void setOpaque(boolean isOpaque): isOpaquefalse, isOpaquetrue public boolean isOpaque(): truefalse
(Java) http://www.swust.net.cn
public void setBorder(Border border),Bordernull public Border getBorder()
(Java) http://www.swust.net.cn
public void setFont(Font f) public Font getFont(Font f) java.awtFont Font public Font(String name,int style,int size) name style
(Java) http://www.swust.net.cn
public void setSize(int width,int height) public void setLocation(int x,int y) x y public Dimension getSize() Dimension
(Java) http://www.swust.net.cn
public Point getLocation(int x,int y) Pointxy public void setBounds(int x,int y,int width,int height) public Rectangle getBounds() Rectanglexy
(Java) http://www.swust.net.cn
public void setEnabled(boolean b) btruebfalse public void setVisible(boolean b) btrue bfalse Window
(Java) http://www.swust.net.cn
public void addFocusListener(FocusListener listener) FocusEvent FocusListener public void focusGained(FocusEvent e) public void focusLost(FocusEvent e)text.addFocusListener(this);public void focusGained(FocusEvent e) {//} public void focusLost(FocusEvent e) {//}
(Java) http://www.swust.net.cn
WindowListener JFrameWindowWindowWindowEvent JFrame addWindowlistener() WindowListener7 public void windowActivated(WindowEvent e)
(Java) http://www.swust.net.cn
public void windowDeactivated(WindowEvent e) public void windowClosing(WindowEvent e) public void windowClosed(WindowEvent e) public void windowIconified(WindowEvent e) public void windowDeiconified(WindowEvent e) public void windowOpened(WindowEvent e)
(Java) http://www.swust.net.cn
(MouseEvent) () 7
(Java) http://www.swust.net.cn
MouseListenerMouseMotionListener MouseListenerMouseMotionListenerMouseEvent MouseListener addMouseMotionListener (MouseListener listener) MouseListener5mousePressed(MouseEvent)
(Java) http://www.swust.net.cn
mouseReleased(MouseEvent e)mouseEntered(MouseEvent e)mouseExited(MouseEvent e)mouseClicked(MouseEvent e)
(Java) http://www.swust.net.cn
MouseMotionListenerMouseMotionListener addMouseMotionListener(MouseListener listener) mouseDragged(MouseEvent e)mouseMoved(MouseEvent e)
(Java) http://www.swust.net.cn
MouseEvent MouseEvent getX()x- getY()y- getClickCount() getModifiers() BUTTON1_MASKBUTTON3_MASKgetSource()
(Java) http://www.swust.net.cn
public static Point convertPoint(Component source, int x, int y,Component destination)Pointsource(x,y) destinationgetX()getY()destination
(Java) http://www.swust.net.cn
MouseEvent convertMouseEvent(Component source, MouseEvent sourceEvent, Component destination) javax.swingSwingUtilities
(Java) http://www.swust.net.cn
PointerInfoSDK1.5java.awtPointerInfo getPointerInfo()PointerInfo PointerInfo pi=MouseInfo.getPointerInfo();
(Java) http://www.swust.net.cn
JPopupMenu public JPopupMenu() public JPopupMenu(String label) label public void show(Component invoker, int x, int y)invokerJPopupMenu() =menu=new JPopupMenu();menu.show(text,e.getX(),e.getY());
(Java) http://www.swust.net.cn
KeyListener addKeyListener() KeyListener3 public void keyPressed(KeyEvent e)keyPressed public void keyTyped(KeyEvent e)keyTyped public void KeyReleased(KeyEvent e)KeyReleased
(Java) http://www.swust.net.cn
public int getKeyCode()keyPressed java VK_KeyEventintVK_0,VK_A,VK_SHIFT,VK_RIGHT keyPressedkeyReleasedkeyTyped
(Java) http://www.swust.net.cn
KeyEvent getModifiers()InputEvent ALT_MASKCTRL_MASK SHIFT_MASK
(Java) http://www.swust.net.cn
JDialog JDialogWindow JDialog getContentPane()
(Java) http://www.swust.net.cn
(Java) http://www.swust.net.cn
javax.swingJOptionPane public static void showMessageDialog (Component parentComponent,String message,String title, int messageType)
(Java) http://www.swust.net.cn
javax.swingJOptionPane public static int showConfirmDialog (Component parentComponent,Object message,String title,int optionType) ,,
(Java) http://www.swust.net.cn
javax.swingJColorChooser public static Color showDialog (Component component,String title,Color initialColor) componenttitleinitialColor
(Java) http://www.swust.net.cn
JFileChooser showDialog(Component parentString s) showOpenDialog(Component parent) showSaveDialog(Component parent) parentparentnull
(Java) http://www.swust.net.cn
Java PrinterJob PrinterJob PrinterJob PrinterJob static PrinterJob getPrinterJob()PrinterJob
(Java) http://www.swust.net.cn
PrinterJob public abstract PageFormatpageDialog (PageFormat page) PageFormat public PageFormat defaultPage() PageFormat
(Java) http://www.swust.net.cn
PrinterJobvoid setPrintable (Printable painter,PageFormat format) formatpageFormat painterPrintable Printable NO_SUCH_PAGEPAGE_EXISTS Printable int print(Graphics graphics, PageFormat pageFormat, int pageIndex)
(Java) http://www.swust.net.cn
Printable com PrinterJobcancel() PrinterJob
(Java) http://www.swust.net.cn
PrinterJob(page mode) public int getLineCount()
(Java) http://www.swust.net.cn
jar.exeJAR JavaJARTom.jarJava-jar java -jar Tom.jar
(Java) http://www.swust.net.cn
JarWindows(moon.mf)Manifest-Version: 1.0Main-Class: ExampleCreated-By: 1.4 Manifest-Version1.0Main-ClassExampleCreated-By1.4moon.mfD:\test
(Java) http://www.swust.net.cn
JARcJARfJARm Tom.jarJavaJavaD:\testjar cfm Tom.jar moon.mf .D:\testjar cfm Tom.jar moon.mf Example.class A.class B.class