|
ahmadiss wrote: in netbeens it write me BUILD SUCCESSFUL
So you have built your program, but you still need to run it in the JVM.
|
|
|
|
|
first thank you for your reply
how to execute it in the jvm ?
I can't run it only with program !!
|
|
|
|
|
|
Well, my French is not very good but it looks like the message says "keytool-genkey-alias-keystore is not recognised as a command or program file name". I suggest you check where this program resides and use the full pathname to run it.
|
|
|
|
|
thank you , I resolved the problem : problem in path
|
|
|
|
|
this is my code. what wrong with my code? i want to save the image on the canvas as a png picture.
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.BufferedImage;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.colorchooser.*;
import javax.swing.event.*;
import java.awt.geom.Line2D;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import javax.imageio.ImageIO;
public class PaintIt extends JFrame implements ActionListener{
public BufferedImage image = new BufferedImage(500, 500, BufferedImage.TYPE_INT_RGB);
JPanel buttonPanel = new JPanel();
Point lastPos = null;
Point startPos = null;
Point finishPos = null;
Graphics g;
JButton save = new JButton("Save");
JButton cancel = new JButton("Cancel");
JButton clear = new JButton("Clear");
JButton proceed = new JButton("Proceed");
JPanel canvas = new JPanel();
int changer = 1;
String path="";
public PaintIt () {
setLocation(100,100);
setSize(600,500);
setTitle("ENCODE SECTION");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
canvas.setBackground(Color.WHITE);
clear.addActionListener(this);
clear.setActionCommand("clear");
save.addActionListener(this);
save.setActionCommand("Save");
cancel.addActionListener(this);
cancel.setActionCommand("Cancel");
proceed.addActionListener(this);
proceed.setActionCommand("Proceed");
buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.LINE_AXIS));
buttonPanel.setBorder(BorderFactory.createEmptyBorder(0, 10, 10, 10));
buttonPanel.add(Box.createHorizontalGlue());
buttonPanel.add(save);
buttonPanel.add(Box.createRigidArea(new Dimension(10, 0)));
buttonPanel.add(clear);
buttonPanel.add(Box.createRigidArea(new Dimension(10, 0)));
buttonPanel.add(cancel);
buttonPanel.add(Box.createRigidArea(new Dimension(10, 0)));
buttonPanel.add(proceed);
getContentPane().add(canvas, BorderLayout.CENTER);
getContentPane().add(buttonPanel, BorderLayout.SOUTH);
setVisible(true);
g = canvas.getGraphics();
g.setColor(Color.BLACK);
canvas.addMouseMotionListener(new MouseMotionListener () {
public void mouseDragged (MouseEvent m) {
Point p = m.getPoint() ;
if (changer==1){
g.drawLine(lastPos.x, lastPos.y, p.x, p.y) ;
}
lastPos = p ;
}
public void mouseMoved (MouseEvent m) {}
});
canvas.addMouseListener(new MouseListener () {
public void mouseClicked(MouseEvent e) {startPos = e.getPoint();}
public void mousePressed(MouseEvent e) {lastPos = e.getPoint();}
public void mouseReleased(MouseEvent e) {
lastPos = null;
finishPos = e.getPoint();
startPos = null;}
public void mouseEntered(MouseEvent e) {}
public void mouseExited(MouseEvent e) {}
});
}
public void actionPerformed(ActionEvent e) {
if("clear".equals(e.getActionCommand())) {
repaint();
}
if("Save".equals(e.getActionCommand())) {
new captureCanvasImage();
}
if("Cancel".equals(e.getActionCommand())) {
dispose();
}
if("Proceed".equals(e.getActionCommand())) {
new encode1Pane();
}
}
class captureCanvasImage {
public void capture(){
Graphics g = image.createGraphics();
canvas.paint(g);
int w = canvas.getWidth();
int h = canvas.getHeight();
BufferedImage image = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);
g.dispose();
try
{
ImageIO.write(image, "jpg", new File("panel.jpg"));
}
catch(IOException ioe)
{
System.out.println("Panel write help: " + ioe.getMessage());
}
}}
public static void main (String [] args) {
PaintIt p = new PaintIt();
p.setVisible(true);
}
}
|
|
|
|
|
Are you invoking the capture method in your captureCanvasImage class?
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
"Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham
|
|
|
|
|
capture method? sorry i'm new to java. can you help me?
|
|
|
|
|
The capture method is in your inner class called captureCanvasImage. Just having a
new captureCanvasImage() inside your event listener won't do.
I did the following and it works:
captureCanvasImage myCanvas = new captureCanvasImage();
myCanvas.capture();
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
"Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham
|
|
|
|
|
oh, thanks. but it save blank black image. I want the drawing. how?
|
|
|
|
|
It is saving as a "blank" canvas in black because inside your capture method, you are creating a new Graphics object, and not using the one that you have in your main class that has the drawing...
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
"Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham
|
|
|
|
|
how should i do to save the image?
|
|
|
|
|
From what I've read on other forums and looking around the 'net, it sounds like you might want to draw to a BufferedImage with the mouse button clicks/hold downs, and take the BufferedImage and draw it to the canvas.
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
"Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham
|
|
|
|
|
nope. i want to draw on the canvas using mouse listener, then i want to save what i have draw into a folder.
|
|
|
|
|
Yes, I understand that is what you are trying to do. I looked around on other forums with people trying the same idea you are working on, and it seems there is a funky dance between the ImageIO methods, Graphics object, and canvas. I'm checking it out with Netbeans, and I'll let you know what I come up with. Your problem with the program has me interested in figuring it out
"The clue train passed his station without stopping." - John Simmons / outlaw programmer
"Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
"Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham
|
|
|
|
|
okay, please help me.
|
|
|
|
|
Here is a solution using double buffering, which is what I think I was suggesting earlier. I could have just posted the individual sections that were changed, but I felt it would be better to just post it all
import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.awt.image.BufferedImage;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.colorchooser.*;
import javax.swing.event.*;
import java.awt.geom.Line2D;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import javax.imageio.ImageIO;
public class PaintIt extends JFrame implements ActionListener{
BufferedImage image = new BufferedImage(600, 500, BufferedImage.TYPE_INT_RGB);
JPanel buttonPanel = new JPanel();
Point lastPos = null;
Point startPos = null;
Point finishPos = null;
Graphics g;
Graphics imageG;
JButton save = new JButton("Save");
JButton cancel = new JButton("Cancel");
JButton clear = new JButton("Clear");
JButton proceed = new JButton("Proceed");
JPanel canvas = new JPanel();
int changer = 1;
String path="";
public PaintIt () {
setLocation(100,100);
setSize(600,500);
setTitle("ENCODE SECTION");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
canvas.setBackground(Color.WHITE);
clear.addActionListener(this);
clear.setActionCommand("clear");
save.addActionListener(this);
save.setActionCommand("Save");
cancel.addActionListener(this);
cancel.setActionCommand("Cancel");
proceed.addActionListener(this);
proceed.setActionCommand("Proceed");
buttonPanel.setLayout(new BoxLayout(buttonPanel, BoxLayout.LINE_AXIS));
buttonPanel.setBorder(BorderFactory.createEmptyBorder(0, 10, 10, 10));
buttonPanel.add(Box.createHorizontalGlue());
buttonPanel.add(save);
buttonPanel.add(Box.createRigidArea(new Dimension(10, 0)));
buttonPanel.add(clear);
buttonPanel.add(Box.createRigidArea(new Dimension(10, 0)));
buttonPanel.add(cancel);
buttonPanel.add(Box.createRigidArea(new Dimension(10, 0)));
buttonPanel.add(proceed);
getContentPane().add(canvas, BorderLayout.CENTER);
getContentPane().add(buttonPanel, BorderLayout.SOUTH);
setVisible(true);
g = canvas.getGraphics();
g.setColor(Color.BLACK);
imageG = image.getGraphics();
imageG.setColor(Color.WHITE);
imageG.fillRect(0,0,600,500);
imageG.setColor(Color.BLACK);
canvas.addMouseMotionListener(new MouseMotionListener () {
public void mouseDragged (MouseEvent m) {
Point p = m.getPoint() ;
if (changer==1){
g.drawLine(lastPos.x, lastPos.y, p.x, p.y);
imageG.drawLine(lastPos.x, lastPos.y, p.x, p.y);
}
lastPos = p;
}
public void mouseMoved (MouseEvent m) {}
});
canvas.addMouseListener(new MouseListener () {
public void mouseClicked(MouseEvent e) {startPos = e.getPoint();}
public void mousePressed(MouseEvent e) {lastPos = e.getPoint();}
public void mouseReleased(MouseEvent e) {
lastPos = null;
finishPos = e.getPoint();
startPos = null;}
public void mouseEntered(MouseEvent e) {}
public void mouseExited(MouseEvent e) {}
});
}
public void actionPerformed(ActionEvent e) {
if("clear".equals(e.getActionCommand())) {
repaint();
}
if("Save".equals(e.getActionCommand())) {
captureCanvasImage myCanvasImage = new captureCanvasImage();
myCanvasImage.capture();
}
if("Cancel".equals(e.getActionCommand())) {
dispose();
}
if("Proceed".equals(e.getActionCommand())) {
}
}
class captureCanvasImage {
public void capture(){
try
{
ImageIO.write(image, "jpg", new File("panel.jpg"));
g.clearRect(0,0,600,500);
}
catch(IOException ioe)
{
System.out.println("Panel write help: " + ioe.getMessage());
}
}}
public static void main (String [] args) {
PaintIt p = new PaintIt();
p.setVisible(true);
}
}
""Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
oh..thank you
but it has some problem, when i save the picture, the canvas will disappear and after i click clear button it will appear back. an i draw back and save, the new image will overlap with the old one. how should save the image without overlap?
|
|
|
|
|
Remove the following line from the capture method:
g.clearRect(0,0,600,500);
In your actionPerformed event handler method, you will want to get rid of the repaint() method, and change it to:
g.clearRect(0,0,600,500);
imageG.setColor(Color.WHITE);
imageG.fillRect(0,0,600,500);
imageG.setColor(Color.BLACK);
This should just clear out the canvas and the double buffered image as well. Good luck to you on the remainder of your project
""Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
clear the canvas, and after i paint back, it save blank black image. how?
|
|
|
|
|
I modified the code in my previous post, it should be:
g.clearRect(0,0,600,500);
imageG.setColor(Color.WHITE);
imageG.fillRect(0,0,600,500);
imageG.setColor(Color.BLACK);
When you invoke the fillRect , it will fill the rectangle with whatever color is the color last set by setColor .
""Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon
|
|
|
|
|
after one time save, and clear, the canvas will disappear too? how to maintain the canvas?
|
|
|
|
|
I have not read through all of the messages in this thread but I get the impression you are trying to mix the drawing and saving code in the same methods. You need to understand how to handle the different parts of the program and why they should be kept separate. Your draw (or paint) method should only be concerned with building an image on screen from some data held in memory. This could be an image file or a set of instructions which the program uses to construct the image on the canvas. That is the only thing the drawing code should be involved in. The saving code should take the information from memory and write it to backing store (disk or other device) without having any interaction with the image on the screen.
|
|
|
|
|
1. Problem:
You add an Actionlistener to your Save-Button but when button is hit, you just instantiate the class but do not call the capture-method.
So edit the call to:
if("Save".equals(e.getActionCommand())) {
System.out.println("action save hit!");
captureCanvasImage bla = new captureCanvasImage();
bla.capture();
|
|
|
|
|
Okay so I have an app widget and I am trying to make a web request and It just keeps failing. Here is the code:
public class IDEAAllotmentTrackerActivity extends AppWidgetProvider {
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager,
int[] appWidgetIds) {
context.startService(new Intent(context, UpdateService.class));
}
public static class UpdateService extends Service {
@Override
public void onStart(Intent intent, int startId) {
RemoteViews updateViews = null;
try {
updateViews = buildUpdate(this);
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
ComponentName thisWidget = new ComponentName(this, IDEAAllotmentTrackerActivity.class);
AppWidgetManager manager = AppWidgetManager.getInstance(this);
manager.updateAppWidget(thisWidget, updateViews);
}
public RemoteViews buildUpdate(Context context) throws ClientProtocolException, IOException{
HttpClient httpclient = new DefaultHttpClient();
HttpResponse response = httpclient.execute(new HttpGet("http://www.google.com"));
StatusLine statusLine = response.getStatusLine();
String pageContent = "";
if(statusLine.getStatusCode() == HttpStatus.SC_OK){
ByteArrayOutputStream out = new ByteArrayOutputStream();
response.getEntity().writeTo(out);
out.close();
pageContent = out.toString();
} else{
response.getEntity().getContent().close();
throw new IOException(statusLine.getReasonPhrase());
}
RemoteViews updateViews = null;
updateViews = new RemoteViews(context.getPackageName(), R.layout.main);
updateViews.setTextViewText(R.id.message, pageContent);
return updateViews;
}
@Override
public IBinder onBind(Intent intent) {
return null;
}
}
}
Then my manifest looks like this:
<application android:label="IDEA allotment">
<receiver android:name=".IDEAAllotmentTrackerActivity" android:label="@string/app_name">
<intent-filter>
<action android:name="android.appwidget.action.APPWIDGET_UPDATE" />
</intent-filter>
<meta-data android:name="android.appwidget.provider" android:resource="@xml/stuff" />
</receiver>
<service android:name=".IDEAAllotmentTrackerActivity$UpdateService" />
</application>
<uses-permission android:name="android.permission.INTERNET" />
<uses-sdk android:targetSdkVersion="15" android:minSdkVersion="11"/>
</manifest>
Any sugestions.
|
|
|
|
|