public class Rutkowski extends javax.swing.JFrame {
public Rutkowski() {
initComponents();
wys = this.getSize().height;
szer = this.getSize().width;
this.setSize(szer,wys-125);
}
int wys;
int szer;
FileDialog fd =new FileDialog(this,"Zapisz",FileDialog.SAVE);
private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {
fd.setVisible(true);
String sciezka = fd.getDirectory() + fd.getFile().split("[.]")[0] + ".txt";
PrintWriter zapis;
try {
zapis = new PrintWriter(sciezka);
for(int i=0 ; i<tabela.getColumnCount();i++){
for(int j=0 ; j<tabela.getModel().getRowCount();j++){
zapis.print(tabela.getModel().getValueAt(i, j));
zapis.print(" ");
}
zapis.println("");
}
zapis.println("");
zapis.close();
log.setText("Plik zapisano.");
} catch (FileNotFoundException ex) {
Logger.getLogger(Rutkowski.class.getName()).log(Level.SEVERE, null, ex);
}
}
private void poleActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
}
int a;
int wylosowana;
int suma;
Random losowa = new Random();
private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {
log.setText("");
suma = 0;
a = Integer.parseInt(pole.getText());
for(int i=0 ; i<tabela.getColumnCount();i++){
for(int j=0 ; j<tabela.getModel().getRowCount();j++){
wylosowana = losowa.nextInt(((a*3)+1)-a)+a;
tabela.getModel().setValueAt(wylosowana, i, j);
if(wylosowana>2*a)suma+=wylosowana;
}
}
etykieta.setText(suma+"");
}
public class Rysowanie extends JPanel {
Color colors[] = { Color.RED, Color.BLUE, Color.GREEN, Color.YELLOW,
Color.BLACK, Color.CYAN, Color.ORANGE, Color.PINK,
Color.DARK_GRAY, new Color(100,100,100), new Color(10,160,100),
new Color(12,120,220), new Color(200,130,30),
new Color(losowa.nextInt(255),losowa.nextInt(255),losowa.nextInt(255)),
};
Color color1;
Color color2;
Color color3;
Color color4;
Color color5;
public Rysowanie() {
this.color1 = colors[losowa.nextInt(colors.length)];
this.color2 = colors[losowa.nextInt(colors.length)];
this.color3 = colors[losowa.nextInt(colors.length)];
this.color4 = colors[losowa.nextInt(colors.length)];
this.color5 = colors[losowa.nextInt(colors.length)];
}
public void paintComponent(Graphics g) {
Graphics2D g2 = (Graphics2D) g;
Rectangle2D rect = new Rectangle2D.Double(0,0,120,120);
Ellipse2D e1 = new Ellipse2D.Double(1,1,57,57);
Ellipse2D e2 = new Ellipse2D.Double(62,1,57,57);
Ellipse2D e3 = new Ellipse2D.Double(1,62,57,57);
Ellipse2D e4 = new Ellipse2D.Double(62,62,57,57);
Ellipse2D e5 = new Ellipse2D.Double(32,32,57,57);
g2.setPaint(Color.WHITE);
g2.fill(rect);
g2.setPaint(color1);
g2.fill(e1);
g2.setPaint(color2);
g2.fill(e2);
g2.setPaint(color3);
g2.fill(e3);
g2.setPaint(color4);
g2.fill(e4);
g2.setPaint(new Color(Math.round((float)Math.random()*255),Math.round((float)Math.random()*255),Math.round((float)Math.random()*255)));
g2.fill(e5);
}
}
private void jMenuItem3ActionPerformed(java.awt.event.ActionEvent evt) {
jPanel2.setLayout(new BorderLayout());
jPanel2.removeAll();
jPanel2.setBorder(BorderFactory.createLineBorder(Color.black));
Rysowanie rys = new Rysowanie();
jPanel2.add(rys);
this.setSize(szer, wys+1);
this.setSize(szer, wys-1);
}