350 likes | 659 Vues
JAVA GUI Swing. http://docs.oracle.com/javase/tutorial/uiswing/start/index.html. İlk Gui ( graphical User Interface ). İmports javax. Content Pane. http:// docs.oracle.com/javase/tutorial/uiswing/components/toplevel.html. JComponent Class.
E N D
JAVA GUI Swing http://docs.oracle.com/javase/tutorial/uiswing/start/index.html
İlk Gui (graphical User Interface) • İmportsjavax
Content Pane • http://docs.oracle.com/javase/tutorial/uiswing/components/toplevel.html
JComponentClass • all Swing components whose names begin with "J" descend from the JComponentclass • JPanel, JScrollPane, JButton, andJTableallinheritfromJcomponent • JComponentFeatures • Tool tips • Painting and borders • Application-wide pluggable look and feel • Custom properties • Support for layout • Support for accessibility • Support for drag and drop • Double buffering • Key bindings
TheJComponentAPI • Customizing Component Appearance • Setting and Getting Component State • Handling Events • Painting Components • Dealing with the Containment Hierarchy • Laying Out Components • Getting Size and Position Information • Specifying Absolute Size and Position
Using TextComponents • http://docs.oracle.com/javase/tutorial/uiswing/examples/components/index.html#TextSamplerDemo
Text Component API • Setting Attributes • Manipulating the Selection • Converting Positions Between the Model and the View • Text Editing Commands • Classes and Interfaces That Represent Documents • Working With Documents • Manipulating Carets and Selection Highlighters • Reading and Writing Text
Visual Java Components • http://docs.oracle.com/javase/tutorial/ui/features/compWin.html
JComboBox • ComboBox.addActionListener( Obje ) • Obje implementsActionListener • ActionPerformed (ActionEvent e)
Java ile Paint işlemleri • Metin Boyama • add(newMyPanel());
Java ile Boyama MyPanel2 class MyPanel extends JPanel{ private intsquareX = 50; private intsquareY = 50; private intsquareW = 20; private intsquareH = 20; publicMyPanel2() { setBorder(BorderFactory.createLineBorder(Color.black)); addMouseListener(newMouseAdapter() { publicvoidmousePressed(MouseEvent e) { moveSquare(e.getX(),e.getY()); } }); addMouseMotionListener(newMouseAdapter() { publicvoidmouseDragged(MouseEvent e) { moveSquare(e.getX(),e.getY()); } }); } private void moveSquare(int x, int y) { int OFFSET = 1; if ((squareX!=x) || (squareY!=y)) { repaint(squareX,squareY,squareW+OFFSET,squareH+OFFSET); squareX=x; squareY=y; repaint(squareX,squareY,squareW+OFFSET,squareH+OFFSET); } } publicDimensiongetPreferredSize() { returnnewDimension(250,200); } protectedvoidpaintComponent(Graphics g) { super.paintComponent(g); g.drawString("This is my custom Panel!",10,20); g.setColor(Color.RED); g.fillRect(squareX,squareY,squareW,squareH); g.setColor(Color.BLACK); g.drawRect(squareX,squareY,squareW,squareH); } }
Paint Methods • publicvoidpaint(Graphics g) java.awt.Component. • protectedvoidpaintComponent(Graphics g) • protectedvoidpaintBorder(Graphics g) • protectedvoidpaintChildren(Graphics g)