Rysowanie figur
Kody źródłowe z odcinka
package pl.am.swing.ramka5;
import javax.swing.*;
import java.awt.*;
public class MojeOkno extends JFrame {
public MojeOkno() {
Toolkit toolkit = Toolkit.getDefaultToolkit();
Dimension rozmiarEkranu = toolkit.getScreenSize();
setTitle("Moje pierwsze okienko");
setBounds(50, 50, rozmiarEkranu.width/2, rozmiarEkranu.height/2);
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setResizable(false);
add(new FiguryComponent());
}
public static void main(String[] args) {
EventQueue.invokeLater(() -> {
MojeOkno mojeOkno = new MojeOkno();
mojeOkno.setVisible(true);
});
}
}
package pl.am.swing.ramka5;
import javax.swing.*;
import java.awt.*;
public class FiguryComponent extends JComponent {
@Override
protected void paintComponent(Graphics g) {
g.drawString("Hello world", 0, 20);
g.drawLine(100, 100, 300, 300);
g.drawRect(100, 100, 200, 200);
//g.drawArc(100, 100, 200, 200, 180, 90);
g.drawOval(100, 100, 200, 200);
}
}