Java - Utilizar variable en clases obtenida atravez de getparameters

   
Vista:

Utilizar variable en clases obtenida atravez de getparameters

Publicado por claudio (1 intervención) el 31/07/2013 00:07:49
Hola

YO se que debe ser super basica me pregunta pero estoy aprendiendo

tengo una aplicacion applet y le envio parametros
os recibo con getparameters, pero debo entregarselos a otra clase del tipo private y no logro realizarlo
si alguien me puede ayudar un poco u orientarme se lo agradeceria
adjunto todo el código marque con NEGRITA donde recibo declaro y necesito utilizar la variable

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
public class MorenaStudioBpt extends JApplet
{
String var2; //DECLARO VARIABLE A UTILIZAR
private static class MainPanel extends JPanel
{
    private JTextField status = new JTextField();
    private ImagePanel selected=null;
    private SaveImageAction saveImageAction;
    private UploadImageAction uploadImageAction;
    private MouseListener mouseListener=new MouseListener();
    private boolean hasServer=false;
    private URL documentBase=null;
 
    private class RemoveAllAction extends AbstractAction implements Runnable
    { RemoveAllAction()
      { super("remove all");
      }
 
      public synchronized void actionPerformed(ActionEvent event)
      { new Thread(this).start();
      }
 
      public synchronized void run()
      { removeAll();
        select(null);
        repaint();
      }
    }
 
    private class AcquireImageAction extends AbstractAction implements Runnable
    {
	AcquireImageAction()
      { super("acquire image");
      }
 
      public synchronized void actionPerformed(ActionEvent event)
      { new Thread(this).start();
      }
 
      public synchronized void run()
      { try
        {
	  status.setText("Working ...");
          MorenaSource source=Morena.selectSource(MainPanel.this);
          if (source!=null)
          { source.setColorMode();
            source.setResolution(100);
            while (true)
            { MorenaImage morenaImage=new MorenaImage(source);
              int imageStatus=morenaImage.getStatus();
              if (imageStatus==ImageConsumer.STATICIMAGEDONE)
              { int imageWidth=morenaImage.getWidth();
                int imageHeight=morenaImage.getHeight();
                int imagePixelSize=morenaImage.getPixelSize();
                ImagePanel image=new ImagePanel(Toolkit.getDefaultToolkit().createImage(morenaImage));
                MainPanel.this.add(image);
                select(image);
                int size=(int)Math.round(Math.sqrt(getComponentCount()));
                setLayout(new GridLayout(size, size));
 
                if (TwainSource.class.isInstance(source))
                {
                  Frame frame=((TwainSource)source).getFrame();
                  status.setText("Done - actual image frame is ["+Math.round(100*frame.left)/100.0+", "+Math.round(100*frame.top)/100.0+"] - ["+Math.round(100*frame.right)/100.0+", "+Math.round(100*frame.bottom)/100.0+"] ...");
                }
                else
                  status.setText("Done - actual image size is "+imageWidth+" x "+imageHeight+" x "+imagePixelSize+" ...");
                validate();
                if (TwainSource.class.isInstance(source) && ((TwainSource)source).hasMoreImages())
                  continue;
              }
              else if (imageStatus==ImageConsumer.IMAGEABORTED)
                status.setText("Aborted, try again ...");
              else if (imageStatus==ImageConsumer.IMAGEERROR)
                status.setText("Failed, try again ...");
              break;
            }
          }
          else
            status.setText("Failed, try again ...");
        }
        catch (NoSuchMethodError error)
        { JOptionPane.showMessageDialog(MainPanel.this, "Previous version of Morena is installed in "+System.getProperty("java.home")+".\nYou have to remove it first.\nClick OK to terminate browser.", "Error", JOptionPane.ERROR_MESSAGE);
          System.exit(0);
        }
        catch (Throwable exception)
        { JOptionPane.showMessageDialog(MainPanel.this, exception.toString(), "Error", JOptionPane.ERROR_MESSAGE);
          exception.printStackTrace();
          status.setText("Failed, try again ...");
        }
        finally
        { try
          { Morena.close();
          }
          catch (Exception exception)
          { exception.printStackTrace();
          }
        }
      }
    }
 
    private class SaveImageAction extends AbstractAction implements Runnable
    { private class Filter extends FileFilter
      { String type;
 
      public void actionPerformed(ActionEvent event)
      { new Thread(this).start();
      }
 
      public synchronized void run()
      { try
        { status.setText("Working ...");
          Image image=selected.getImage();
          BufferedImage bufferedImage=new BufferedImage(image.getWidth(null), image.getHeight(null), BufferedImage.TYPE_INT_RGB);
          bufferedImage.createGraphics().drawImage(image, 0, 0, null);
          JFileChooser chooser=new JFileChooser();
//        Java 1.6 introduced a comfortable ImageIO.getWriterFileSuffixes() method.
          String e[] = ImageIO.getWriterFormatNames();
          for (int i=0; i<e.length; i++)
            chooser.addChoosableFileFilter(new Filter(e));
          int result=chooser.showSaveDialog(MainPanel.this);
          if (result==JFileChooser.APPROVE_OPTION)
          { String ext=chooser.getFileFilter().getDescription();
            ext=ext.substring(0, ext.indexOf(' ')).toLowerCase();
            File file=chooser.getSelectedFile();
            String name=file.getName();
            if (!name.endsWith(ext))
              file=new File(file.getParentFile(), name+"."+ext);
            ImageIO.write(bufferedImage, ext, file);
          }
        }
        catch (Throwable exception)
        { JOptionPane.showMessageDialog(MainPanel.this, exception.toString(), "Error", JOptionPane.ERROR_MESSAGE);
          exception.printStackTrace();
          status.setText("Failed, try again ...");
        }
      }
 
      public boolean isEnabled()
      { return selected != null;
      }
    }
 
    private class UploadImageAction extends AbstractAction implements Runnable
  {
	UploadImageAction()
      { super("upload to server");
      }
 
      public void actionPerformed(ActionEvent event)
      { new Thread(this).start();
      }
 
      public synchronized void run()
      { try
        {
	  status.setText("Working ...");
          Image image=selected.getImage();
          ByteArrayOutputStream tmp=new ByteArrayOutputStream();
          BufferedImage bufferedImage=new BufferedImage(image.getWidth(null), image.getHeight(null), BufferedImage.TYPE_INT_RGB);
          bufferedImage.createGraphics().drawImage(image, 0, 0, null);
          ImageIO.write(bufferedImage, "jpg", tmp);
          tmp.close();
          int contentLength=tmp.size();
          if (contentLength>1024*1024)
            throw new Exception("Image is too big to upload");
          URL uploadURL=new URL(documentBase, "upload.php?c='" + var2 + "'"); //ENVIO VARIABLE PERO SE CAE
          HttpURLConnection connection=(HttpURLConnection)uploadURL.openConnection();
          connection.setRequestMethod("POST");
          connection.setDoOutput(true);
          connection.setUseCaches(false);
          connection.setDefaultUseCaches(false);
          connection.setRequestProperty("content-type", "img/jpeg");
          connection.setRequestProperty("content-length", String.valueOf(contentLength));
          OutputStream out=connection.getOutputStream();
          out.write(tmp.toByteArray());
          out.close();
          InputStream in=connection.getInputStream();
          int c;
          while ((c=in.read())!=-1)
            System.err.write(c);
          in.close();
          URL imageURL=new URL(documentBase, connection.getHeaderField("file-name"));
          status.setText("Done - image is uploaded to "+imageURL+" (for at least 5 minutes) ...");
        }
        catch (Throwable exception)
        { JOptionPane.showMessageDialog(MainPanel.this, exception.toString(), "Error", JOptionPane.ERROR_MESSAGE);
          exception.printStackTrace();
          status.setText("Failed, try again ...");
        }
      }
 
      public boolean isEnabled()
      { return hasServer && selected != null;
      }
    }
 
    private class MouseListener extends MouseAdapter
    { public void mouseClicked(MouseEvent event)
      { select((ImagePanel)event.getComponent());
      }
    }
 
    private class ImagePanel extends JPanel
    { private Image image;
      int imageWidth;
      int imageHeight;
 
      ImagePanel(Image image)
      { this.image=image;
        imageWidth=image.getWidth(null);
        imageHeight=image.getHeight(null);
        addMouseListener(mouseListener);
      }
 
      public Image getImage()
      { return image;
      }
 
      public void paint(Graphics g)
      { super.paint(g);
        int panelWidth=getWidth()-6;
        int panelHeight=getHeight()-6;
        double horizontalRatio=(double)panelWidth/imageWidth;
        double verticalRatio=(double)panelHeight/imageHeight;
        if (horizontalRatio>verticalRatio)
          g.drawImage(image, (int)(panelWidth-imageWidth*verticalRatio)/2+3, 3, (int)(imageWidth*verticalRatio), (int)(imageHeight*verticalRatio), this);
        else
          g.drawImage(image, 3, 3, (int)(imageWidth*horizontalRatio), (int)(imageHeight*horizontalRatio), this);
      }
 
    }
 
 
    void select(ImagePanel image)
    { if(selected != null)
      selected.setBorder(null);
      selected = image;
      if(selected != null)
      {
        selected.setBorder(new LineBorder(Color.blue, 1));
        saveImageAction.setEnabled(true);
        uploadImageAction.setEnabled(hasServer);
      } else
      {
        saveImageAction.setEnabled(false);
        uploadImageAction.setEnabled(false);
      }
    }
 
    MainPanel(Container container, URL documentBase)
    { this.documentBase=documentBase;
      status.setEditable(false);
      hasServer=documentBase!=null && documentBase.getProtocol().indexOf("http")!=-1;
      container.add(new ToolBar(), BorderLayout.NORTH);
      container.add(this, BorderLayout.CENTER);
      container.add(status, BorderLayout.SOUTH);
      setLayout(new GridLayout(1, 1));
    }
  }
 
  public void init()
  {
[i]	var2=getParameter("pasada");   //AQUI RECIVO DESDE HTML CON APPLET
	new MainPanel(getContentPane(), getDocumentBase());
  }
 
  public static void main(String args[])
  { JFrame frame=new JFrame("Morena Studio");
    frame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    new MainPanel(frame.getContentPane(), null);
    frame.setBounds(100, 100, 600, 400);
    frame.setVisible(true);
  }
}
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder