Kod: |
java.security.AccessControlException: access denied (java.io.FilePermission slike\new.gif read)
at java.security.AccessControlContext.checkPermission(Unknown Source) at java.security.AccessController.checkPermission(Unknown Source) at java.lang.SecurityManager.checkPermission(Unknown Source) at java.lang.SecurityManager.checkRead(Unknown Source) at sun.awt.SunToolkit.getImageFromHash(Unknown Source) at sun.awt.SunToolkit.getImage(Unknown Source) at javax.swing.ImageIcon.<init>(Unknown Source) at javax.swing.ImageIcon.<init>(Unknown Source) at tangenta.init(tangenta.java:183) at sun.applet.AppletPanel.run(Unknown Source) at java.lang.Thread.run(Unknown Source) |
Kod: |
import javax.swing.*; import java.awt.*; import java.awt.event.*; import java.lang.Math; import java.applet.Applet; import java.io.File; import java.util.Vector; class pravac { private float k,l; private Color boja; public pravac(float a,float b,Color c) { k=a; l=b; boja=c; } public float racunaj(float x) { return (k*x+l); } public float getK() {return k;} public float getL() {return l;} public Color getColor() {return boja;} } class platno extends Canvas { private int opcija=0; // 0=cratj tangentu, 1=zoom, 2=move private Color boja; private Vector pravci; private pravac tmp; private float x,y,x1,y1; private int moveX1,moveX2,moveY1,moveY2; private float intervalX=10; //dakle interval crtanja je [-10,10] private float intervalY=2; //dakle interval crtanja je [-2,2] private float pomakX=0; //centrirano je na ishodiste private float pomakY=0; public platno() { pravci=new Vector(); pravci.addElement(new pravac(0,0,Color.BLACK)); //os X pravci.addElement(new pravac(2000,0,Color.BLACK)); //os Y this.addMouseMotionListener(new MouseMotionListener() { public void mouseDragged(MouseEvent e) { if(opcija==1) { moveX2=e.getX(); moveY2=e.getY(); intervalX=intervalX+(moveX1-moveX2)*(float)(0.005); intervalY=intervalY+(moveY1-moveY2)*(float)(0.005); if(intervalX<0) intervalX=(float)0.0001; //da se ne izokrenu osi if(intervalY<0) intervalY=(float)0.0001; moveX1=moveX2; moveY1=moveY2; repaint(); } else if(opcija==2) { moveX2=e.getX(); moveY2=e.getY(); pomakX=pomakX+(moveX1-moveX2)*(float)(0.005); pomakY=pomakY+(moveY2-moveY1)*(float)(0.005); moveX1=moveX2; moveY1=moveY2; repaint(); } } public void mouseMoved(MouseEvent e) {} }); this.addMouseListener(new MouseListener() { public void mouseClicked(MouseEvent e) { if(opcija==0) { crtajTangentu(e.getX()); repaint(); } } public void mouseEntered(MouseEvent e) {} public void mouseExited(MouseEvent e) {} public void mousePressed(MouseEvent e) { if(opcija==1 || opcija==2) { moveX1=e.getX(); moveY1=e.getY(); } } public void mouseReleased(MouseEvent e) {} }); } private float funkcija(float x) {return (float)Math.cos((double)x);} private float derivacija(float x) {return (-1)*(float)Math.sin((double)x);} public void setOpcija(int i) {opcija=i;} public void setBoja(Color c) {boja=c;} public void crtajTangentu(int X) { int Width=this.getWidth(); int Height=this.getHeight(); x=(2*intervalX*X)/Width-intervalX+pomakX; //realna tocka u kojoj crtamo tangentu y=funkcija(x); float K=derivacija(x); float L=(y-K*x); pravci.addElement(new pravac(K,L,boja)); } public void paint(Graphics g) { int Width=this.getWidth(); int Height=this.getHeight(); String labelX=String.valueOf(intervalX+pomakX); String labelY=String.valueOf(intervalY+pomakY); String labelX1=String.valueOf(-intervalX+pomakX); String labelY1=String.valueOf(-intervalY+pomakY); g.setColor(Color.BLACK); g.drawString(labelX,Width-40,Height/2); g.drawString(labelX1,2,Height/2); g.drawString(labelY,Width/2,20); g.drawString(labelY1,Width/2,Height-2); for(int i=0;i<Width;i=i+3) { x=(float)i; x1=(float)(i+3); y=funkcija((2*intervalX*x)/Width-intervalX+pomakX); //iz x-a na ekranu tazimo x u stvarnosti y1=funkcija((2*intervalX*x1)/Width-intervalX+pomakX); y=Height/2-((Height/2)*y)/intervalY+(pomakY*Height)/(2*intervalY); //sada nam opet rebaju koordinate na ekranu y1=Height/2-((Height/2)*y1)/intervalY+(pomakY*Height)/(2*intervalY); g.drawLine((int)x,(int)y,(int)x1,(int)y1); } if(!pravci.isEmpty()) { for(int i=0;i!=pravci.size();i++) { tmp=(pravac)pravci.get(i); for(int j=0;j<Width;j=j+10) { x=(float)j; x1=(float)(j+10); y=tmp.racunaj((2*intervalX*x)/Width-intervalX+pomakX); y1=tmp.racunaj((2*intervalX*x1)/Width-intervalX+pomakX); y=Height/2-((Height/2)*y)/intervalY+(pomakY*Height)/(2*intervalY); //sada nam opet rebaju koordinate na ekranu y1=Height/2-((Height/2)*y1)/intervalY+(pomakY*Height)/(2*intervalY); g.setColor(tmp.getColor()); g.drawLine((int)x,(int)y,(int)x1,(int)y1); } } } } } public class tangenta extends JApplet { private JPanel opcije; private platno slika; private JLabel pomoc; private JButton novi,tang,zoom,move; private JRadioButton R,G,B,Black; private ButtonGroup boje; public static void main(String[] args) { tangenta moja=new tangenta(); moja.init(); } public void init() { opcije = new JPanel(); opcije.setBorder(BorderFactory.createTitledBorder("opcije ")); opcije.setLayout(new BorderLayout()); novi = new JButton(new ImageIcon("slike"+File.separator+"new.gif")); novi.setBorder(BorderFactory.createEmptyBorder(0,2,4,1)); tang = new JButton(new ImageIcon("slike"+File.separator+"tang.gif")); tang.setBorder(BorderFactory.createEmptyBorder(0,1,4,1)); zoom = new JButton(new ImageIcon("slike"+File.separator+"zoom.gif")); zoom.setBorder(BorderFactory.createEmptyBorder(0,1,4,1)); move = new JButton(new ImageIcon("slike"+File.separator+"move.gif")); move.setBorder(BorderFactory.createEmptyBorder(0,1,4,2)); R = new JRadioButton("R"); R.setForeground(Color.RED); G = new JRadioButton("G"); G.setForeground(Color.GREEN); B = new JRadioButton("B"); B.setForeground(Color.BLUE); Black = new JRadioButton("CRNO"); Black.setForeground(Color.BLACK); boje=new ButtonGroup(); boje.add(R);boje.add(G);boje.add(B);boje.add(Black); Black.setSelected(true); JPanel gumbi=new JPanel(); gumbi.add(novi); gumbi.add(tang); gumbi.add(zoom); gumbi.add(move); opcije.add(gumbi,BorderLayout.WEST); pomoc=new JLabel(); opcije.add(pomoc,BorderLayout.CENTER); JPanel b=new JPanel(); b.add(R); b.add(G); b.add(B); b.add(Black); opcije.add(b,BorderLayout.EAST); this.getContentPane().setLayout(new BorderLayout()); this.getContentPane().add(opcije,BorderLayout.NORTH); slika=new platno(); this.getContentPane().add(slika); } public void reset() { this.getContentPane().remove(slika); slika=new platno(); this.getContentPane().add(slika); slika.repaint(); } public void start() { R.addMouseListener(new MouseListener() { public void mouseClicked(MouseEvent e) { slika.setOpcija(0); slika.setBoja(Color.RED); } public void mouseEntered(MouseEvent e) {pomoc.setText("Novo crtanje grafa");} public void mouseExited(MouseEvent e) {pomoc.setText("");} public void mousePressed(MouseEvent e) {} public void mouseReleased(MouseEvent e) {} }); G.addMouseListener(new MouseListener() { public void mouseClicked(MouseEvent e) { slika.setOpcija(0); slika.setBoja(Color.GREEN); } public void mouseEntered(MouseEvent e) {pomoc.setText("Novo crtanje grafa");} public void mouseExited(MouseEvent e) {pomoc.setText("");} public void mousePressed(MouseEvent e) {} public void mouseReleased(MouseEvent e) {} }); B.addMouseListener(new MouseListener() { public void mouseClicked(MouseEvent e) { slika.setOpcija(0); slika.setBoja(Color.BLUE); } public void mouseEntered(MouseEvent e) {pomoc.setText("Novo crtanje grafa");} public void mouseExited(MouseEvent e) {pomoc.setText("");} public void mousePressed(MouseEvent e) {} public void mouseReleased(MouseEvent e) {} }); Black.addMouseListener(new MouseListener() { public void mouseClicked(MouseEvent e) { slika.setOpcija(0); slika.setBoja(Color.BLACK); } public void mouseEntered(MouseEvent e) {pomoc.setText("Novo crtanje grafa");} public void mouseExited(MouseEvent e) {pomoc.setText("");} public void mousePressed(MouseEvent e) {} public void mouseReleased(MouseEvent e) {} }); novi.addMouseListener(new MouseListener() { public void mouseClicked(MouseEvent e) { reset(); } public void mouseEntered(MouseEvent e) {pomoc.setText("Novo crtanje grafa");} public void mouseExited(MouseEvent e) {pomoc.setText("");} public void mousePressed(MouseEvent e) {} public void mouseReleased(MouseEvent e) {} }); tang.addMouseListener(new MouseListener() { public void mouseClicked(MouseEvent e) { slika.setOpcija(0); if(R.isSelected()) {slika.setBoja(Color.RED);} else if(G.isSelected()) {slika.setBoja(Color.GREEN);} else if(B.isSelected()) {slika.setBoja(Color.BLUE);} else {slika.setBoja(Color.BLACK);} } public void mouseEntered(MouseEvent e) {pomoc.setText("Crtaj tangentu. (Odaberite boju) ");} public void mouseExited(MouseEvent e) {pomoc.setText("");} public void mousePressed(MouseEvent e) {} public void mouseReleased(MouseEvent e) {} }); zoom.addMouseListener(new MouseListener() { public void mouseClicked(MouseEvent e) { slika.setOpcija(1); } public void mouseEntered(MouseEvent e) {pomoc.setText("Zumiraj. (Van: vuci lijevo gore) (Unutra: vuci desno dolje)");} public void mouseExited(MouseEvent e) {pomoc.setText("");} public void mousePressed(MouseEvent e) {} public void mouseReleased(MouseEvent e) {} }); move.addMouseListener(new MouseListener() { public void mouseClicked(MouseEvent e) { slika.setOpcija(2); } public void mouseEntered(MouseEvent e) {pomoc.setText("Pomakni graf");} public void mouseExited(MouseEvent e) {pomoc.setText("");} public void mousePressed(MouseEvent e) {} public void mouseReleased(MouseEvent e) {} }); } } |
output generated using printer-friendly topic mod. Vremenska zona: GMT + 01:00.