netbeans tablica i grafika

0

Witam mam problem. Kompletnie się nie znam na programowaniu, a za kilka godzin mam ostatnią poprawę kolokwium z informatyki mam do zrobienia zadanie, robię je od ok 10h i prawie nic mi nie wyszło. Czy ktoś jest jeszcze o tej porze na forum i mógłby mi podpowiedzieć jakiej komendy użyć, żeby wygenerować sume licz wyświetlanych w tabeli większych od 3a. i jak narycować taki rysunek. W załączniku jest cała treść. i tutaj dodam to co napisałam do tej pory. Bardzo prosze o jakieś wskazówki

import java.awt.Color;
import java.awt.Graphics;
import java.io.File;
import java.io.IOException;
import java.util.Random;
import java.util.Scanner;
import javax.swing.JOptionPane;
import javax.swing.JPanel;

//import javax.swing.*;

/*

  • To change this template, choose Tools | Templates
  • and open the template in the editor.
    */

/*

  • Marta.java

  • Created on 2011-06-09, 1901
    /
    /
    *

  • @Author Marta
    */
    public class Marta extends javax.swing.JFrame {

    Scanner we;
    PanelGraficzny p;
    Color kolor;

    /** Creates new form Marta */
    public Marta() {
    initComponents();

     p = new PanelGraficzny();
     p.setBackground(Color.white);
     p.setBounds(0, 170, 120, 120);
    

    }
    class PanelGraficzny extends JPanel {
    @Override
    protected void paintComponent (Graphics g) {
    kolor = new Color((int)(Math.random()*256), (int)(Math.random()*256), (int)(Math.random()*256));

         g.setColor(kolor);
         g.fillPolygon();
     }
    

    }
    /** This method is called from within the constructor to

    • initialize the form.

    • WARNING: Do NOT modify this code. The content of this method is

    • always regenerated by the Form Editor.
      */
      @SuppressWarnings("unchecked")
      // <editor-fold defaultstate="collapsed" desc="Generated Code">
      private void initComponents() {

      jScrollPane1 = new javax.swing.JScrollPane();
      jTable1 = new javax.swing.JTable();
      jLabel1 = new javax.swing.JLabel();
      jLabel2 = new javax.swing.JLabel();
      jTextField1 = new javax.swing.JTextField();
      jTextField2 = new javax.swing.JTextField();
      jMenuBar1 = new javax.swing.JMenuBar();
      jMenu1 = new javax.swing.JMenu();
      jMenuItem1 = new javax.swing.JMenuItem();
      jMenuItem2 = new javax.swing.JMenuItem();
      jMenuItem3 = new javax.swing.JMenuItem();

      setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

      jTable1.setModel(new javax.swing.table.DefaultTableModel(
      new Object [][] {
      {null, null, null, null, null},
      {null, null, null, null, null},
      {null, null, null, null, null},
      {null, null, null, null, null},
      {null, null, null, null, null}
      },
      new String [] {
      "A", "B", "C", "D", "E"
      }
      ) {
      Class[] types = new Class [] {
      java.lang.Integer.class, java.lang.Integer.class, java.lang.Integer.class, java.lang.Integer.class, java.lang.Integer.class
      };

       public Class getColumnClass(int columnIndex) {
           return types [columnIndex];
       }
      

      });
      jScrollPane1.setViewportView(jTable1);

      jLabel1.setText("jLabel1");

      jLabel2.setText("jLabel2");

      jTextField1.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
      jTextField1ActionPerformed(evt);
      }
      });

      jTextField2.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
      jTextField2ActionPerformed(evt);
      }
      });

      jMenu1.setText("Tabela");
      jMenu1.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
      jMenu1ActionPerformed(evt);
      }
      });

      jMenuItem1.setText("Losuj");
      jMenuItem1.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
      jMenuItem1ActionPerformed(evt);
      }
      });
      jMenu1.add(jMenuItem1);

      jMenuItem2.setText("Zapis");
      jMenuItem2.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
      jMenuItem2ActionPerformed(evt);
      }
      });
      jMenu1.add(jMenuItem2);

      jMenuItem3.setText("Rysuj");
      jMenuItem3.addActionListener(new java.awt.event.ActionListener() {
      public void actionPerformed(java.awt.event.ActionEvent evt) {
      jMenuItem3ActionPerformed(evt);
      }
      });
      jMenu1.add(jMenuItem3);

      jMenuBar1.add(jMenu1);

      setJMenuBar(jMenuBar1);

      javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
      getContentPane().setLayout(layout);
      layout.setHorizontalGroup(
      layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(layout.createSequentialGroup()
      .addGap(39, 39, 39)
      .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addComponent(jScrollPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 359, javax.swing.GroupLayout.PREFERRED_SIZE)
      .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
      .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE)
      .addGap(68, 68, 68)
      .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, 72, javax.swing.GroupLayout.PREFERRED_SIZE))
      .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
      .addComponent(jLabel1)
      .addGap(101, 101, 101)
      .addComponent(jLabel2)
      .addGap(26, 26, 26)))
      .addContainerGap(78, Short.MAX_VALUE))
      );
      layout.setVerticalGroup(
      layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
      .addGroup(layout.createSequentialGroup()
      .addContainerGap()
      .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 113, javax.swing.GroupLayout.PREFERRED_SIZE)
      .addGap(44, 44, 44)
      .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
      .addComponent(jLabel1)
      .addComponent(jLabel2))
      .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 50, Short.MAX_VALUE)
      .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
      .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
      .addComponent(jTextField2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
      .addGap(45, 45, 45))
      );

      pack();
      }// </editor-fold>

    private void jTextField2ActionPerformed(java.awt.event.ActionEvent evt) {
    // TODO add your handling code here:
    }

    private void jMenu1ActionPerformed(java.awt.event.ActionEvent evt) {

// TODO add your handling code here:
}

private void jMenuItem1ActionPerformed(java.awt.event.ActionEvent evt) {
     int b = 0;
    Random r = new Random();
    try {
        int a = Integer.parseInt(jTextField1.getText());
        int n = a;
        int m = 5 * a;
        for (int i = 0; i < jTable1.getRowCount(); i++) {
            for (int j = 0; j < jTable1.getColumnCount(); j++) {
                b = a + r.nextInt(m - n + 1);
                jTable1.setValueAt(b, i, j);
            }

        }
        int z = 3*a;

         int suma = 0;
        
        for (int i = 0; i < (int)jTable1.getRowCount(); i++) {
            for (int j = 0; j < (int)jTable1.getColumnCount(); j++) {
                //if(z < (int)jTable1.getValueAt(i, j))  {
                //if(2>1) {
                   //
            }
            }
         jLabel1.setText("Suma wynosi" + " " + suma);
    } catch (Exception e) {
        JOptionPane.showMessageDialog(null, "Błąd danych");
    }   // TODO add your handling code here:
}

private void jMenuItem2ActionPerformed(java.awt.event.ActionEvent evt) {

int suma = 0;
try {
we = new Scanner(new File("dane83.txt"));
we.useDelimiter(" ");
while (we.hasNextInt()) {
suma = we.nextInt()*we.nextInt() ;
}
jTextField2.setText("" + suma);
} catch (IOException e) {
JOptionPane.showMessageDialog(this, e.getMessage());
} finally {
if (we != null) {
we.close();
}
}
}

private void jMenuItem3ActionPerformed(java.awt.event.ActionEvent evt) {
add(p);

p.setBackground(Color.white);
repaint(); // TODO add your handling code here:
}

private void jTextField1ActionPerformed(java.awt.event.ActionEvent evt) {
    // TODO add your handling code here:
}

/**
 * @param args the command line arguments
 */
public static void main(String args[]) {
    java.awt.EventQueue.invokeLater(new Runnable() {

        public void run() {
            new Marta().setVisible(true);
        }
    });
}
// Variables declaration - do not modify
private javax.swing.JLabel jLabel1;
private javax.swing.JLabel jLabel2;
private javax.swing.JMenu jMenu1;
private javax.swing.JMenuBar jMenuBar1;
private javax.swing.JMenuItem jMenuItem1;
private javax.swing.JMenuItem jMenuItem2;
private javax.swing.JMenuItem jMenuItem3;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JTable jTable1;
private javax.swing.JTextField jTextField1;
private javax.swing.JTextField jTextField2;
// End of variables declaration

}

0

To co wklejasz jest nie czytelne zwłaszcza załącznik...
Na przyszłość kod w znaczniki a zdjęcia wyraźne...
Powodzenia! Czy coś tam ;]

1 użytkowników online, w tym zalogowanych: 0, gości: 1