java gui swing
DESCRIPTION
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. - PowerPoint PPT PresentationTRANSCRIPT
JAVA GUI Swinghttp://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 all Swing components whose names begin with "J"
descend from the JComponent class JPanel, JScrollPane, JButton, and JTableall inherit
from Jcomponent JComponent Features
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
The JComponent API 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 Text Components
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 t
he View Text Editing Commands Classes and Interfaces That Represent Docum
ents 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
Bileşen Eklemek
CF
Rastgele Renkler
Alternatif ActionListener
GridLayout örneği
JButton
JToggle
JRadioButton
JRadioButton
JComboBox ComboBox.addActionListener( Obje ) Obje implements ActionListener
ActionPerformed (ActionEvent e)
JCheckBox
Item state Changed
Java ile Paint işlemleri Metin Boyama
add(new MyPanel());
Java ile Boyama MyPanel2class MyPanel extends JPanel {private int squareX = 50; private int squareY = 50; private int squareW = 20; private int squareH = 20; public MyPanel2() { setBorder(BorderFactory.createLineBorder(Color.black)); addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent e) { moveSquare(e.getX(),e.getY()); } }); addMouseMotionListener(new MouseAdapter() { public void mouseDragged(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); } } public Dimension getPreferredSize() { return new Dimension(250,200); } protected void paintComponent(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 public void paint(Graphics g)
java.awt.Component.
protected void paintComponent(Graphics g) protected void paintBorder(Graphics g) protected void paintChildren(Graphics g)
Key Events .. KeyListener