|
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.
|
|
|
|
|
I don't know much about android. But how did you decide that the request is failing? Did you end up with an error? If so what is it, post it here?
If you've never failed... You've never lived...
|
|
|
|
|
Since Android 4.0 (SDK 14), it is no longer allowed to have network communications in the UI thread.
The solution is to move the code where you download files into a background thread, for example with a Runnable. Make sure to keep your updateViews.setTextViewText() calls in the UI thread though, with for example a Handler.
modified 13-Sep-18 21:01pm.
|
|
|
|
|
Thanks a lot! Here is the code I used:
new Thread(new Runnable() {
public void run() {
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpGet httpGet = new HttpGet("http://www.google.com/pxi");
ResponseHandler<String> resHandler = new BasicResponseHandler();
String page = "";
try {
page = httpClient.execute(httpGet, resHandler);
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
final String p = page;
Log.e("response" , page);
test.post(new Runnable() {
public void run() {
test.setText(p);
}
});
}
}).start();
Also this page I found helpful:
http://developer.android.com/guide/components/processes-and-threads.html[^]
|
|
|
|
|
I have a problem when i get value from another class, the error message show
"unreported exception java.io.FileNotFoundException; must be caught or declared to be thrown"
This is my main code
package testtimer;
import testing.testing_1234;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.Timer;
import java.util.Date;
import java.io.*;
import java.text.*;
import java.util.*;
import java.sql.*;
import javax.swing.*;
import javax.swing.JTable;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.sql.Connection;
import java.util.Iterator;
/**
*
* @author tan
*/
public class testing_page extends javax.swing.JFrame {
testing_1234 appsetting = new testing_1234();
String strc=appsetting.getcname();
public rxpooltesting() {
initComponents();
}
@SuppressWarnings("unchecked")
private void initComponents() {
setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 400, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 300, Short.MAX_VALUE)
);
pack();
}
public static void main(String args[]) {
java.awt.EventQueue.invokeLater(new Runnable() {
public void run() {
new testing_page().setVisible(true);
}
});
}
}
This is my class:
package testing;
import java.io.*;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.io.FileWriter;
import java.io.BufferedWriter;
import java.util.Properties;
import java.io.FileNotFoundException;
public class readsetting {
private String PropertiesPath = "C:TestTimer/src/testtimer/setting.properties";
private String strcname;
public readsetting()
{
}
public readsetting(String strurl,String struname,String strpword,String strcname,String strxpool,
String stridcounter,String strtemppol,String strxlog,String strlogfile,String strDB,
String strservice)
{}
public String getcname() throws FileNotFoundException, IOException{
FileInputStream is = new FileInputStream( PropertiesPath );
Properties dbProps = new Properties();
dbProps.load(is);
strcname=dbProps.getProperty("classnames");
return strcname;
}
public void setcname(String cname){
this.strcname = cname;
}
}
Thanks.
|
|
|
|
|
Did you actually read the error message? getcname declares thrown exceptions, so you have to catch or declare them as thrown wherever you call it. That means you can't use getcname in a static initialiser, because there's no way to catch the exception.
|
|
|
|
|
I have some files dont know how to decrypt them i mean these are using to conduct exam, atleast i am unable to keep all the data for future preparation also
i am attached a rar file download This Link in it i kept a folder which contains six files 5 of the are encpyted from them one is question other four are options of that question and one of them the solution of the question
i need to decrpyt so please tell me the way to decrypt and to view them
|
|
|
|
|
I don't know why - but I felt fancy and wanted to see if our new virus detection is working (They said it's so much better...).
The files are complete crap. There is nothing in them. What kind of file are those supposed to be? They are HTML labeled, but I guess they should be something else!?
|
|
|
|
|
It contains no virus or any thing that harms the computer i just need some types of encryption and decryption that are used in tomcat jsp
I want to break it totally
|
|
|
|
|
kmkmahesh wrote: I want to break it totally
Then you are in the wrong place. We do not assist in hacking.
Programming is work, it isn't finger painting. Luc Pattyn
|
|
|
|
|
believe me. There is nothing in these files.
What should be in there and where did you get them?
|
|
|
|
|
With the effort you're putting into this, you could just learn the course material properly and pass the exam legitimately.
|
|
|
|
|
Programming is work, it isn't finger painting. Luc Pattyn
|
|
|
|
|
Hello everyone! I have been trying for three days on Eclipse 4.2 version.I have done all the work regarding Tomcat installation and configuration and JDBC 5.1 plugin installation.The problem is this;when I try to make a connection to the MySql server,it rejects although I provide it with proper info such as port no 3306,database "test".By the way I have no password for mysql server.Any help plz.thnx
Always believe in God and never let misfortunes make you give up
|
|
|
|
|
Hi,
That is pretty vague; ou could Google for examples and find things such as this[^]; or you could show us the relevant parts of your code and the exact exception information you are getting, if you want specific help.
|
|
|
|
|
countered the downvote
V.
|
|
|
|
|
|
Write a simple program that does NOTHING but a jdbc connection.
That means that it will NOT have any GUI components.
That means that it will NOT have any Tomcat/JEE specific code.
Set the connection string.
Run it.
Look at the exception.
Most likely causes are incorrect connection string, no access to the database and/or that the database is not running.
Only the first is solvable in java.
|
|
|
|
|
Does the MySQL server run on the same machine? If no, configure it to accept connections from different computers.
Do you want to login as root from a different computer? Also that must be configured.
Have you tried a user with password?
Can you connect to your MySQL server with a MySQL tool, e.g. MySQLAdministrator.exe or MySQLQueryBrowser.exe?
|
|
|
|