Skocz do zawartości
Forum komputerowe PC Centre

margo

Użytkownicy
  • Zawartość

    3
  • Rejestracja

  • Ostatnia wizyta

Reputacja

0 Neutralny

O margo

  • Tytuł
    Jestem tu nowy
  1. eeee.... fajne:) z C i C++ miałam trochę do czynienia ale nie dużo W C++ nie pasuje mi trochę to odśmiecanie tzn. to że muszę to robić sama, bo nie zawsze wiem kiedy mogę, kiedy nie mogę, a kiedy muszę ale może faktycznie warto spróbować z C# skoro tak go zachwalasz
  2. Tzn. program oddałam i wiem już dlaczego miniaturki się nie wyświetlały /po prostu folder images był w folderze z programem a powinien być w folderze z klasą/, do tego udało mi się wczoraj dojść samej. Ale jak zrobię z tego jar to nadal się nie wyświetlają /robią to tylko gdy dam run bezpośrednio z kompilatora/. Ale sam fakt oddania programu nie wpływa na to, że nadal jestem ciekawa jak zrobić resztę Chyba Java zaczęła mi się podobać Może to nowa pasja...?
  3. Witam wszystkich, mam problem bo na jutro a właściwie na dziś muszę oddać projekt na infę i muszę to skończyć Problem polega na tym, że w swoim programie /graficzna aplikacja okienkowa/ mam tam listę rozwijaną z której wybiera się teksturę do figury ... No - i sęk w tym, że miniaturek tekstur mi nie wyświetla na tej liście. I jak zrobię z tego jar to też nie ma tekstur tylko maluje mi na czarno. Podejrzewam, że chodzi o to, że chyba nie są wsadzone do programu tylko pobiera je sobie jako link czy coś. Nie wiem - nie znam się. Załączam kod i byłabym b. wdzięczna jakby ktoś mi to poprawił /* * Main.java * * Created on 16 czerwiec 2007, 18:13 */ package rysujwreszcie; /** * * @author Małgorzata Topór * @matematyka1@o2.pl * @version 09-06-07 */ import java.awt.Color; import java.awt.Component; import java.awt.Container; import java.awt.Dimension; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.awt.event.KeyEvent; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import java.awt.event.MouseMotionListener; import java.io.File; import javax.swing.ButtonGroup; import javax.swing.ImageIcon; import javax.swing.JColorChooser; import javax.swing.JComboBox; import javax.swing.JFileChooser; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JList; import javax.swing.JMenu; import javax.swing.JMenuBar; import javax.swing.JMenuItem; import javax.swing.JRadioButton; import javax.swing.ListCellRenderer; import javax.swing.event.ChangeEvent; import javax.swing.event.ChangeListener; public class Program extends JFrame implements ChangeListener, ActionListener , MouseListener ,MouseMotionListener { /** * */ private static final long serialVersionUID = 1L; int zw=1,klik=0,wypelnienie=0; int xx1,xx2,yy1,yy2; int x0,x1,y0,y1; float [] x = new float[6]; float [] y = new float[6]; ImageIcon[] images; String[] textureStrings = {"tekstura1", "tekstura2", "tekstura3","tekstura4","tekstura5", "tekstura6", "tekstura7","tekstura8", "tekstura9", "tekstura10", "tekstura11","tekstura12", "tekstura13","tekstura14","tekstura15", "tekstura16", "tekstura17","tekstura18", "tekstura19", "tekstura20", "tekstura21", "tekstura22", "tekstura23","tekstura24","tekstura25"}; JFileChooser wplik; JColorChooser tcc; JMenuItem save; JMenuItem open; JRadioButton okrag,elipsa,lamana,brak,tekstura,prostokat,kwadrat, kolor; ButtonGroup wybor,wybor2; Color color = new Color(50,100,150); byte przycisk; Rysunek rysunek = new Rysunek(); public Program(){ super("Rysuj wreszcie!"); setBounds(10,10,800,665); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); rysunek.czyszczenie(1000,1000); addMouseListener(this); zrobMenu(); addMouseMotionListener(this); } public void mouseDragged(final MouseEvent e) { if(przycisk==1) { rysunek.zmiana2(); x1=e.getX()-205; y1=e.getY()-45; rysuj(); } } public void mouseMoved(final MouseEvent e) { } public void mouseClicked(final MouseEvent e) { } public void mousePressed(final MouseEvent e) { if(e.getButton()==MouseEvent.BUTTON1||e.getButton()==MouseEvent.BUTTON2||e.getBu tton()==MouseEvent.BUTTON3) { rysunek.zmiana1(); przycisk=1; x0=e.getX()-205; y0=e.getY()-45; x1=x0; y1=y0; rysuj(); } } public void mouseReleased(final MouseEvent e) { } public void mouseEntered(final MouseEvent e) { } public void mouseExited(final MouseEvent e) { } public void stateChanged(final ChangeEvent e) { color = tcc.getColor(); } public void actionPerformed(final ActionEvent evt) { final Object source = evt.getSource(); if(source==brak) { wypelnienie=0; } if(source==kolor) { wypelnienie=1; } if(source==tekstura) { wypelnienie=2; } if (source == okrag) { zw=1; klik=0; } if (source == elipsa) { zw=2; klik=0; } if (source == lamana) { zw=3; klik=0; } if(source == prostokat) { klik=0; zw=5; } if(source == kwadrat) { klik=0; zw=6; } if(source == save) { final int savefile = wplik.showSaveDialog(this); if (savefile == JFileChooser.APPROVE_OPTION) { String nazwa; nazwa = wplik.getSelectedFile().toString(); final File saveas = new File(nazwa+".jpg"); System.out.println("Saving as " + saveas); rysunek.zapisz(saveas); System.out.println("Zapisalem Plik"); } } if(source == open) { final int openfile = wplik.showOpenDialog(this); if (openfile == JFileChooser.APPROVE_OPTION) { String nazwa; nazwa = wplik.getSelectedFile().toString(); final File openas = new File(nazwa+".jpg"); System.out.println("Saving as " + openas); rysunek.zapisz(openas); System.out.println("Zapisalem Plik"); } } } public void rysuj() { rysunek.ustawienia(wypelnienie,color); switch (zw) { case 1: rysunek.okrag(x0,y0,x1,y1); break; case 2: rysunek.elipsa(x0,y0,x1,y1); break; case 3: rysunek.lamana(x0,y0,x1,y1); break; case 4: if(klik==6) { rysunek.szescian(x,y); klik=0; } break; case 5: rysunek.prostokat(x0,y0,x1,y1); break; case 6: rysunek.kwadrat(x0,y0,x1); break; } } private void zrobMenu(){ wplik =new JFileChooser(); images = new ImageIcon[textureStrings.length]; final Integer[] intArray = new Integer[textureStrings.length]; for (int i = 0; i < textureStrings.length; i++) { intArray = new Integer(i); images = createImageIcon("images/" + textureStrings + ".jpg"); if (images != null) { images.setDescription(textureStrings); } } final JMenuBar listwamenu = new JMenuBar(); setJMenuBar(listwamenu); final JMenu zmiany = new JMenu("Menu"); listwamenu.add(zmiany); zmiany.setMnemonic(KeyEvent.VK_Z); zmiany.setToolTipText("Menu Zmiany"); save = new JMenuItem("Zapisz plik jpg"); zmiany.add(save); save.setToolTipText("Zapisuje do pliku jpg"); save.addActionListener(this); open = new JMenuItem("Otwórz plik jpg"); zmiany.add(open); open.setToolTipText("Otwiera plik jpg"); open.addActionListener(this); //wybór figury okrag = new JRadioButton("Okrąg"); okrag.setBounds(0,0,200,20); okrag.addActionListener(this); okrag.setSelected(true); prostokat = new JRadioButton("Prostokat"); prostokat.setBounds(0,20,200,20); prostokat.addActionListener(this); prostokat.setSelected(true); kwadrat = new JRadioButton("Kwardrat"); kwadrat.setBounds(0,20,200,20); kwadrat.addActionListener(this); kwadrat.setSelected(true); elipsa = new JRadioButton("Elipsa"); elipsa.setBounds(0,40,200,20); elipsa.addActionListener(this); lamana = new JRadioButton("Prosta"); lamana.setBounds(0,60,200,20); lamana.addActionListener(this); wybor = new ButtonGroup(); wybor.add(okrag); wybor.add(prostokat); wybor.add(kwadrat); wybor.add(elipsa); wybor.add(lamana); //wybór wypełnienia brak = new JRadioButton("Bez Wypelnienia"); brak.setBounds(0,120,200,20); brak.addActionListener(this); brak.setSelected(true); kolor = new JRadioButton("Wypelninie Kolorem"); kolor.setBounds(0,140,200,20); kolor.addActionListener(this); tekstura = new JRadioButton("Wypelnienie Tekstura"); tekstura.setBounds(0,160,200,20); tekstura.addActionListener(this); wybor2 = new ButtonGroup(); wybor2.add(brak); wybor2.add(kolor); wybor2.add(tekstura); tcc = new JColorChooser(); tcc.getSelectionModel().addChangeListener(this); tcc.setBounds(0,350,450,350); final JComboBox petList = new JComboBox(intArray); final ComboBoxRenderer renderer= new ComboBoxRenderer(); renderer.setPreferredSize(new Dimension(50,60)); petList.setRenderer(renderer); petList.setMaximumRowCount(5); petList.setBounds(500,372,80,60); petList.setToolTipText("Wybierz teksture"); rysunek.setBounds(200,0,650,350); final Container z = getContentPane(); z.setLayout(null); z.add(petList); z.add(rysunek); z.add(tcc); z.add(prostokat); z.add(kwadrat); z.add(okrag); z.add(elipsa); z.add(lamana); z.add(brak); z.add(kolor); z.add(tekstura); } protected static ImageIcon createImageIcon(final String path) { final java.net.URL imgURL = Program.class.getResource(path); if (imgURL != null) { return new ImageIcon(imgURL); } else { System.err.println("Couldn't find file: " + path); return null; } } public static void main(final String[] arguments){ final Program program = new Program(); program.show(); } class ComboBoxRenderer extends JLabel implements ListCellRenderer { /** * */ private static final long serialVersionUID = 1L; public Component getListCellRendererComponent( final JList list, final Object value, final int index, final boolean isSelected, final boolean cellHasFocus) { final int selectedIndex = ((Integer)value).intValue(); rysunek.obrazek(selectedIndex+1); final ImageIcon icon = images[selectedIndex]; final String pet; pet = textureStrings[selectedIndex]; setIcon(icon); return this; } } } ____________ /* * Rysunek.java * * Created on 16 czerwiec 2007, 18:13 * */ package rysujwreszcie; /** * * @author Malgorzata Topór * @matematyka1@o2.pl * @version 09-06-07 */ import java.awt.*; import javax.swing.*; import java.awt.geom.*; import java.awt.image.*; import java.io.*; import javax.imageio.*; class Rysunek extends JPanel{ int wypelnienie; Color kolor; BufferedImage image = new BufferedImage(650,350,BufferedImage.TYPE_INT_RGB); Graphics2D imagerys = image.createGraphics(); BufferedImage image4 = new BufferedImage(650,350,BufferedImage.TYPE_INT_RGB); Graphics2D imagerys4 = image4.createGraphics(); BufferedImage image2 = new BufferedImage(50,50,BufferedImage.TYPE_INT_RGB); Graphics2D imagerys2 = image2.createGraphics(); public void czyszczenie(int x,int y) { imagerys4.setBackground(Color.white); imagerys4.clearRect(0,0,x,y); imagerys.setBackground(Color.white); imagerys.clearRect(0,0,x,y); repaint(); } public void zmiana1() { imagerys4.drawImage(image,0,0,null); repaint(); } public void zmiana2() { imagerys.drawImage(image4,0,0,null); repaint(); } public void ustawienia(int wyp,Color kol) { kolor = kol; wypelnienie = wyp; } public void zapisz(File saveas) { try { ImageIO.write(image,"jpeg",saveas); } catch (IOException ie) { System.out.println(ie); } image.flush(); } public void szescian(float x[],float y[]) { GeneralPath obiekt = new GeneralPath(GeneralPath.WIND_EVEN_ODD,1); obiekt.moveTo(x[0],y[0]); obiekt.lineTo(x[1],y[1]); obiekt.lineTo(x[2],y[2]); obiekt.lineTo(x[3],y[2]); obiekt.lineTo(x[4],y[4]); obiekt.lineTo(x[5],y[5]); obiekt.closePath(); namaluj(obiekt); } public void obrazek(int ble) { Toolkit toolkit = Toolkit.getDefaultToolkit(); Image image3 = toolkit.getImage("images/tekstura"+ble+".jpg"); MediaTracker media = new MediaTracker(this); media.addImage(image3,0); try { media.waitForID(0); } catch (InterruptedException ie) { System.err.println(ie); System.exit(1); } imagerys2.drawImage(image3,0,0,null); } public void prostokat(double x1,double y1,double x2,double y2) { Rectangle2D.Double prostokat; prostokat = new Rectangle2D.Double(1,1,1,1); //tylko po to aby nie wyskakiwal blad prostokat may not have been initialized if(x1<x2&&y1<y2) prostokat = new Rectangle2D.Double(x1,y1,x2-x1,y2-y1); if(x1<x2&&y1>y2) prostokat = new Rectangle2D.Double(x1,y2,x2-x1,y1-y2); if(x1>x2&&y1<y2) prostokat = new Rectangle2D.Double(x2,y1,x1-x2,y2-y1); if(x1>x2&&y1>y2) prostokat = new Rectangle2D.Double(x2,y2,x1-x2,y1-y2); namaluj(prostokat); } public void kwadrat (double x1,double y1,double x2) { Rectangle2D.Double kwadrat; kwadrat = new Rectangle2D.Double(1,1,1,1); //tylko po to aby nie wyskakiwal blad kwadrat may not have been initialized if(x1<x2) kwadrat = new Rectangle2D.Double(x1,y1,x2-x1,x2-x1); if(x1>x2) kwadrat = new Rectangle2D.Double(x2,y1,x1-x2,x1-x2); namaluj(kwadrat); } public void elipsa (double x1,double y1,double x2,double y2) { Ellipse2D.Double elipsa; elipsa = new Ellipse2D.Double(1,1,1,1); //tylko po to aby nie wyskakiwal blad elipsa may not have been initialized if(x1<x2&&y1<y2) elipsa = new Ellipse2D.Double(x1,y1,x2-x1,y2-y1); if(x1<x2&&y1>y2) elipsa = new Ellipse2D.Double(x1,y2,x2-x1,y1-y2); if(x1>x2&&y1<y2) elipsa = new Ellipse2D.Double(x2,y1,x1-x2,y2-y1); if(x1>x2&&y1>y2) elipsa = new Ellipse2D.Double(x2,y2,x1-x2,y1-y2); namaluj(elipsa); } public void okrag(double x1, double y1, double x2, double y2) { double promien; promien=Math.pow(Math.pow(x2-x1,2)+Math.pow(y2-y1,2),0.5); Ellipse2D.Double okrag = new Ellipse2D.Double(x1-promien,y1-promien,2*promien,2*promien); namaluj(okrag); } public void zmiana(int x1, int y1,int x2,int y2) { Image ppp1; //ppp1 = image.getSubimage(0,0,650,350).getScaledInstance(650,350,2); int x=Math.abs(x1-x2); int y=Math.abs(y1-y2); // System.out.println(x1+" "+y1); //System.out.println(x2+" "+y2); System.out.println(x+" "+y); if(x1<x2&&y1<y2) { ppp1 = image.getSubimage(x1,y1,x,y).getScaledInstance(650,350,2); imagerys.drawImage(ppp1,0,0,null); } if(x1<x2&&y1>y2) { ppp1 = image.getSubimage(x1,y2,x,y).getScaledInstance(650,350,2); imagerys.drawImage(ppp1,0,0,null); } if(x1>x2&&y1<y2) { ppp1 = image.getSubimage(x2,y1,x,y).getScaledInstance(650,350,2); imagerys.drawImage(ppp1,0,0,null); } if(x1>x2&&y1>y2) { ppp1 = image.getSubimage(x2,y2,x,y).getScaledInstance(650,350,2); imagerys.drawImage(ppp1,0,0,null); } repaint(); } public void lamana(double x1, double y1, double x2, double y2) { Line2D.Double linia = new Line2D.Double(x1,y1,x2,y2); namaluj(linia); } public void namaluj(Shape ppp) { Rectangle2D.Double elipsa = new Rectangle2D.Double(1,1,50,50); imagerys.setStroke(new BasicStroke(1)); if(wypelnienie==2) { imagerys.setPaint(new TexturePaint(image2 ,elipsa)); imagerys.draw(ppp); imagerys.fill(ppp); } if(wypelnienie==1) { imagerys.setColor(kolor); imagerys.fill(ppp); imagerys.draw(ppp); } if(wypelnienie==0) { imagerys.setColor(kolor); imagerys.draw(ppp); ; } repaint(); } public void paintComponent(Graphics g) { super.paintComponent(g); Graphics2D g2 = (Graphics2D)g; Rectangle2D.Double elipsa = new Rectangle2D.Double(0,0,50,50); g2.drawImage(image,0,0,null); } } I jeszcze jakby mi ktoś mogł powiedzieć jak się kopiuje i obraca obiekty (figury) i przenosi to by już rewelacyjnie było
×
×
  • Dodaj nową pozycję...