Viete mi pomoct ako v jave vykreslit tri kruhy vedla seba, ktore budu mat roznu farbu?
Fórum › Java
Java - vykreslenie kruhu nejakej farby

Tady to máš, kdyby si chtěl něco vysvětlit napiš.
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Graphics;
import javax.swing.JFrame;
import javax.swing.JPanel;
/**
*
* @author Vaškovi
*/
public class Kruhy extends JPanel {
public Kruhy() {
repaint();
}
@Override
public void paint(Graphics g) {
//jeden kruh černé barvy
g.setColor(Color.black);
g.drawOval(0, 0, getHeight(), getHeight()); // umístěn u kraje; velikost je podle výšky panelu
//druhý kruh červené barvy
g.setColor(Color.red);
g.drawOval(getHeight(), 0, getHeight(), getHeight()); // umístěn hned vedle prvního; velikost jako u předchozího
//třetí kruh modré barvy
g.setColor(Color.blue);
g.drawOval((getHeight())*2, 0, getHeight(), getHeight()); // umístěn hned vedle druhého; velikost jako u předchozího
}
public static void main(String[] args) {
JFrame jf = new JFrame("Tři kruhy");
jf.getContentPane().add(new Kruhy(), BorderLayout.CENTER);
jf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
jf.pack();
jf.setResizable(false);
jf.setVisible(true);
jf.setBackground(Color.white);
int sirka= 600,vyska = 200;
jf.setSize(sirka,vyska);
java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
jf.setBounds((screenSize.width-sirka)/2, (screenSize.height-vyska)/2, sirka, vyska);
}
}

Přidej příspěvek
Toto téma je starší jak čtvrt roku – přidej svůj příspěvek jen tehdy, máš-li k tématu opravdu co říct!
Ano, opravdu chci reagovat → zobrazí formulář pro přidání příspěvku
×Vložení zdrojáku
×Vložení obrázku
×Vložení videa
Aktuálně jsou podporována videa ze serverů YouTube, Vimeo a Dailymotion.
×






























































Uživatelé prohlížející si toto vlákno
Uživatelé on-line: 0 registrovaných, 40 hostů
Podobná vlákna
Točenie v kruhu — založil Anonym
Vykreslenie grafov — založil Anonymní uživatel
Vykreslenie obrázku — založil Majo
Problém s vypočítáním povrchu kruhu — založil David10101
Jednoduché vykreslení křivky (kruhu) — založil Matěj Andrle
Moderátoři diskuze