jQuery not working, help me solve the error
I recently posted a question about some jQuery code (The other post), but
that didn't work and I can't find the problem, please check:
[http://jsfiddle.net/Qqe89/][2]. You'll neeed to read the other post to
understand this problem...
Monday, 2 September 2013
JButton with background Image changing on mouse hover
JButton with background Image changing on mouse hover
I'm trying to display an JButton with an image on it, but I can't figure
out how to get Mousehover work on this. The normal display of the image is
working, tough. Also it would be nice, if the text drawn on the button
could be centered.
import java.awt.*;
import java.io.IOException;
import java.net.URL;
import javax.imageio.ImageIO;
import javax.swing.JButton;
import javax.swing.JFrame;
public class ImageButtonTest {
private static JButton imageButton;
public static void main(String[] args) throws IOException {
JFrame frm = new JFrame();
frm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frm.setSize(90, 27);
frm.setLocation(50, 50);
Image image = ImageIO.read(new
URL("http://i.imgur.com/bitgM6l.png"));
Image imageHover = ImageIO.read(new
URL("http://i.imgur.com/dt81BWk.png"));
imageButton = new ImageButton(image, imageHover);
imageButton.setText("Download");
frm.add(imageButton);
frm.pack();
frm.setVisible(true);
}
static class ImageButton extends JButton {
private Image image, imageHover;
private boolean hover;
ImageButton(Image image, Image imageHover) {
this.image = image;
this.hover = false;
addMouseListener(new java.awt.event.MouseAdapter() {
@Override
public void mouseEntered(java.awt.event.MouseEvent evt) {
hover = true;
repaint();
}
@Override
public void mouseExited(java.awt.event.MouseEvent evt) {
hover = false;
repaint();
}
});
};
@Override
protected void paintComponent(Graphics g) {
if(isEnabled()) {
Graphics2D g2 = (Graphics2D) g.create();
g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
g2.setFont(new Font("Arial", Font.PLAIN, 12));
g2.setColor(Color.WHITE);
if(hover) {
g2.drawImage(imageHover, 0, 0, getWidth(),
getHeight(), this);
} else {
g2.drawImage(image, 0, 0, getWidth(), getHeight(), this);
}
g2.drawString(getText(), 20, getHeight() / 2 + 5);
g2.dispose();
} else {
super.paintComponent(g);
}
}
}
}
I'm trying to display an JButton with an image on it, but I can't figure
out how to get Mousehover work on this. The normal display of the image is
working, tough. Also it would be nice, if the text drawn on the button
could be centered.
import java.awt.*;
import java.io.IOException;
import java.net.URL;
import javax.imageio.ImageIO;
import javax.swing.JButton;
import javax.swing.JFrame;
public class ImageButtonTest {
private static JButton imageButton;
public static void main(String[] args) throws IOException {
JFrame frm = new JFrame();
frm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frm.setSize(90, 27);
frm.setLocation(50, 50);
Image image = ImageIO.read(new
URL("http://i.imgur.com/bitgM6l.png"));
Image imageHover = ImageIO.read(new
URL("http://i.imgur.com/dt81BWk.png"));
imageButton = new ImageButton(image, imageHover);
imageButton.setText("Download");
frm.add(imageButton);
frm.pack();
frm.setVisible(true);
}
static class ImageButton extends JButton {
private Image image, imageHover;
private boolean hover;
ImageButton(Image image, Image imageHover) {
this.image = image;
this.hover = false;
addMouseListener(new java.awt.event.MouseAdapter() {
@Override
public void mouseEntered(java.awt.event.MouseEvent evt) {
hover = true;
repaint();
}
@Override
public void mouseExited(java.awt.event.MouseEvent evt) {
hover = false;
repaint();
}
});
};
@Override
protected void paintComponent(Graphics g) {
if(isEnabled()) {
Graphics2D g2 = (Graphics2D) g.create();
g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,
RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
g2.setFont(new Font("Arial", Font.PLAIN, 12));
g2.setColor(Color.WHITE);
if(hover) {
g2.drawImage(imageHover, 0, 0, getWidth(),
getHeight(), this);
} else {
g2.drawImage(image, 0, 0, getWidth(), getHeight(), this);
}
g2.drawString(getText(), 20, getHeight() / 2 + 5);
g2.dispose();
} else {
super.paintComponent(g);
}
}
}
}
Should I fix Xcode 5 'Semantic issue: undeclared selector'?
Should I fix Xcode 5 'Semantic issue: undeclared selector'?
I'm trying to upgrade my app with Xcode5 but encountered a number of
'Semantic issues' in a third party library (the MagicalRecord one). The
quickest way to do 'fix' this might be using the:
#pragma GCC diagnostic ignored "-Wundeclared-selector"
(from: How to get rid of the 'undeclared selector' warning)
compiler directive, but my gut-feeling says this is not the appropriate
way to do this. A small code sample with the above error:
+ (NSEntityDescription *)
MR_entityDescriptionInContext:(NSManagedObjectContext *)context {
if ([self respondsToSelector:@selector(entityInManagedObjectContext:)])
{
NSEntityDescription *entity = [self
performSelector:@selector(entityInManagedObjectContext:)
withObject:context];
return entity;
}
else
{
NSString *entityName = [self MR_entityName];
return [NSEntityDescription entityForName:entityName
inManagedObjectContext:context];
}
}
where the entityInManagedObjectContext: method is not defined anywhere.
Any suggestions on how to best fix these types of errors, thanks in advance?!
I'm trying to upgrade my app with Xcode5 but encountered a number of
'Semantic issues' in a third party library (the MagicalRecord one). The
quickest way to do 'fix' this might be using the:
#pragma GCC diagnostic ignored "-Wundeclared-selector"
(from: How to get rid of the 'undeclared selector' warning)
compiler directive, but my gut-feeling says this is not the appropriate
way to do this. A small code sample with the above error:
+ (NSEntityDescription *)
MR_entityDescriptionInContext:(NSManagedObjectContext *)context {
if ([self respondsToSelector:@selector(entityInManagedObjectContext:)])
{
NSEntityDescription *entity = [self
performSelector:@selector(entityInManagedObjectContext:)
withObject:context];
return entity;
}
else
{
NSString *entityName = [self MR_entityName];
return [NSEntityDescription entityForName:entityName
inManagedObjectContext:context];
}
}
where the entityInManagedObjectContext: method is not defined anywhere.
Any suggestions on how to best fix these types of errors, thanks in advance?!
Dynamically added link button disappeared on button click leaving an empty column
Dynamically added link button disappeared on button click leaving an empty
column
The datagrid reads from several xml files, so I create the columns
dynamically, and added a templatefield as the last column.
A link button is added in the templatefield using RowDataBound.
Private Sub GridItem_RowDataBound(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.GridViewRowEventArgs) Handles
GridItem.RowDataBound
Try
If e.Row.RowType = DataControlRowType.DataRow Then
Dim linkb As New LinkButton
linkb.Text = "Delete"
linkb.ID = "LinkDeleteItem"
linkb.OnClientClick = "javascript:DeleteItem('" &
Convert.ToString(e.Row.RowIndex) & "')"
e.Row.Cells(GridItem.Columns.Count - 1).Controls.Add(linkb)
End If
Catch ex As Exception
lblMessage.Text = ex.Message
End Try
End Sub
Everything works fine.
But when I click a button outside the gridview, to open a window to add a
new item to the grid, the linkbuttons disappear. But the column is still
there.
If I just close the new window without saving a new data (which will
prompt the grid to rebind), the column remains empty. I had to reload the
gridview for the linkbuttons to appear.
Is it because the linkbuttons are created on rowdatabound? How should I
solve this?
column
The datagrid reads from several xml files, so I create the columns
dynamically, and added a templatefield as the last column.
A link button is added in the templatefield using RowDataBound.
Private Sub GridItem_RowDataBound(ByVal sender As Object, ByVal e As
System.Web.UI.WebControls.GridViewRowEventArgs) Handles
GridItem.RowDataBound
Try
If e.Row.RowType = DataControlRowType.DataRow Then
Dim linkb As New LinkButton
linkb.Text = "Delete"
linkb.ID = "LinkDeleteItem"
linkb.OnClientClick = "javascript:DeleteItem('" &
Convert.ToString(e.Row.RowIndex) & "')"
e.Row.Cells(GridItem.Columns.Count - 1).Controls.Add(linkb)
End If
Catch ex As Exception
lblMessage.Text = ex.Message
End Try
End Sub
Everything works fine.
But when I click a button outside the gridview, to open a window to add a
new item to the grid, the linkbuttons disappear. But the column is still
there.
If I just close the new window without saving a new data (which will
prompt the grid to rebind), the column remains empty. I had to reload the
gridview for the linkbuttons to appear.
Is it because the linkbuttons are created on rowdatabound? How should I
solve this?
Sunday, 1 September 2013
Not receiving a seg fault when expected
Not receiving a seg fault when expected
I'm in the process of learning how to use pointers and structs in C.
Naturally, I'm trying to deliberately break my code to further understand
how the language works. Here is some test code that works as I expected it
to work:
#include <stdio.h>
#include <stdlib.h>
struct pair {
int x;
int y;
};
typedef struct pair pair;
void p_struct( pair ); //prototype
int main( int argc, char** argv ) {
pair *s_pair;
int size, i;
printf( "Enter the number of pair to make: " );
scanf( "%d", &size );
getchar();
printf( "\n" );
s_pair = (pair*)malloc( size * sizeof(pair) );
for( i = 0; i < size; i++ ) {
s_pair[i].x = i;
s_pair[i].y = i;
p_struct( s_pair[i] );
}
getchar();
return (EXIT_SUCCESS);
}
void p_struct( pair s_pair ) {
printf( "\n%d %d\n", s_pair.x, s_pair.y );
}
As previously stated, this code is functional as far as I can tell.
I then decided to modify a part of the code like so:
for( i = 0; i < size + 3; i++ ) {
s_pair[i].x = i;
s_pair[i].y = i;
p_struct( s_pair[i] );
}
This modification did not produce the seg fault error that I expected it
would. All of the "pairs" were printed despite me exceeding the buffer I
explicitly set when assigning a value to my variable size using the scanf
function.
As I understand pointers (correct me if I'm wrong), a contiguous block of
memory of size size*sizeof(pair) is reserved by the memory manager in the
heap when I called the malloc function for my pointer of type pair s_pair.
What I did was I exceeded the last assigned address of memory when I
modified my for loop to the condition i < size + 3.
If I'm understanding this correctly, did my pointer exceed its reserved
memory limit and just so happen to be in the clear because nothing
adjacent and to the right of it was occupied by other data? Is this normal
behaviour when overflowing a buffer?
To add, I did receive a seg fault when I tested with a for loop condition
of i < size + 15. The thing is, it still prints the output. As in, it
prints the pair "0 0" to pair "24 24" when size = 10 on the screen as per
the p_struct function I made. The program crashes by seg fault only after
it gets to one of those getchar()s at the bottom. How on earth could my
program assign values to pairs that exceed the buffer, print them on the
screen, and then all of a sudden decide to crash on seg fault when it gets
to getchar()? It seemed to have no issue with i < size + 3 (despite it
still being wrong).
For the record, I also tested this behaviour with a regular pointer array:
int size, i, *ptr;
scanf( "%d", &size );
ptr = (int*)malloc( size * sizeof(int) );
for( i = 0; i < size + 15; i++ )
ptr[i] = i;
This produces the exact same result as above. At i < size + 3 there
doesn't seem to be any issue with seg faults.
Finally, I tested with an array, too:
int i, array[10];
for( i = 0; i < 25; i++ )
array[i] = i;
For the condition i < 25, I get a seg fault without fail. When I change it
to i < 15, I receive no seg fault.
If I remember correctly, the only difference between an array of pointers
and an array is that the memory allocated to an array is located on the
stack as opposed to the heap (not sure about this). With that in mind, and
considering the fact that i < 15 when array[10] doesn't produce any seg
faults, why would i < 25 be an issue? Isn't the array at the top of the
stack during that for loop? Why would it care about 100 extra bytes when
it didn't care about 60 extra bytes? Why isn't the ceiling for that array
buffer all the way to the end of whatever arbitrary chunk of memory is
reserved for the whole stack?
Hopefully all of this made sense to whoever decides to read a slightly
inebriated man's ramblings.
I'm in the process of learning how to use pointers and structs in C.
Naturally, I'm trying to deliberately break my code to further understand
how the language works. Here is some test code that works as I expected it
to work:
#include <stdio.h>
#include <stdlib.h>
struct pair {
int x;
int y;
};
typedef struct pair pair;
void p_struct( pair ); //prototype
int main( int argc, char** argv ) {
pair *s_pair;
int size, i;
printf( "Enter the number of pair to make: " );
scanf( "%d", &size );
getchar();
printf( "\n" );
s_pair = (pair*)malloc( size * sizeof(pair) );
for( i = 0; i < size; i++ ) {
s_pair[i].x = i;
s_pair[i].y = i;
p_struct( s_pair[i] );
}
getchar();
return (EXIT_SUCCESS);
}
void p_struct( pair s_pair ) {
printf( "\n%d %d\n", s_pair.x, s_pair.y );
}
As previously stated, this code is functional as far as I can tell.
I then decided to modify a part of the code like so:
for( i = 0; i < size + 3; i++ ) {
s_pair[i].x = i;
s_pair[i].y = i;
p_struct( s_pair[i] );
}
This modification did not produce the seg fault error that I expected it
would. All of the "pairs" were printed despite me exceeding the buffer I
explicitly set when assigning a value to my variable size using the scanf
function.
As I understand pointers (correct me if I'm wrong), a contiguous block of
memory of size size*sizeof(pair) is reserved by the memory manager in the
heap when I called the malloc function for my pointer of type pair s_pair.
What I did was I exceeded the last assigned address of memory when I
modified my for loop to the condition i < size + 3.
If I'm understanding this correctly, did my pointer exceed its reserved
memory limit and just so happen to be in the clear because nothing
adjacent and to the right of it was occupied by other data? Is this normal
behaviour when overflowing a buffer?
To add, I did receive a seg fault when I tested with a for loop condition
of i < size + 15. The thing is, it still prints the output. As in, it
prints the pair "0 0" to pair "24 24" when size = 10 on the screen as per
the p_struct function I made. The program crashes by seg fault only after
it gets to one of those getchar()s at the bottom. How on earth could my
program assign values to pairs that exceed the buffer, print them on the
screen, and then all of a sudden decide to crash on seg fault when it gets
to getchar()? It seemed to have no issue with i < size + 3 (despite it
still being wrong).
For the record, I also tested this behaviour with a regular pointer array:
int size, i, *ptr;
scanf( "%d", &size );
ptr = (int*)malloc( size * sizeof(int) );
for( i = 0; i < size + 15; i++ )
ptr[i] = i;
This produces the exact same result as above. At i < size + 3 there
doesn't seem to be any issue with seg faults.
Finally, I tested with an array, too:
int i, array[10];
for( i = 0; i < 25; i++ )
array[i] = i;
For the condition i < 25, I get a seg fault without fail. When I change it
to i < 15, I receive no seg fault.
If I remember correctly, the only difference between an array of pointers
and an array is that the memory allocated to an array is located on the
stack as opposed to the heap (not sure about this). With that in mind, and
considering the fact that i < 15 when array[10] doesn't produce any seg
faults, why would i < 25 be an issue? Isn't the array at the top of the
stack during that for loop? Why would it care about 100 extra bytes when
it didn't care about 60 extra bytes? Why isn't the ceiling for that array
buffer all the way to the end of whatever arbitrary chunk of memory is
reserved for the whole stack?
Hopefully all of this made sense to whoever decides to read a slightly
inebriated man's ramblings.
Replace DELETE for UPDATE with a trigger on SQLite
Replace DELETE for UPDATE with a trigger on SQLite
Is it possible in SQLite to make an update instead of a delete within a
trigger ? I.e, I got these two tables:
CREATE TABLE author (authorid INTEGER PRIMARY KEY, temporal NUMERIC);
CREATE TABLE comment (id INTEGER PRIMARY KEY, text TEXT, authorid INTEGER,
FOREIGN KEY(authorid) REFERENCES author(authorid));
When a deletion of an author is attempted and there's any comment
referencing that author i want to update the "temporal" field and abort
deletion.
I've tested different approaches with triggers but i have not found a way
to do the two things, make the update and abort the delete. I can abort
the delete (though in this case it's not necessary as it is enforced by
the foreign key constraint) or make the update (though the delete will
remove the record, so the update has no effect)
Is it possible in SQLite to make an update instead of a delete within a
trigger ? I.e, I got these two tables:
CREATE TABLE author (authorid INTEGER PRIMARY KEY, temporal NUMERIC);
CREATE TABLE comment (id INTEGER PRIMARY KEY, text TEXT, authorid INTEGER,
FOREIGN KEY(authorid) REFERENCES author(authorid));
When a deletion of an author is attempted and there's any comment
referencing that author i want to update the "temporal" field and abort
deletion.
I've tested different approaches with triggers but i have not found a way
to do the two things, make the update and abort the delete. I can abort
the delete (though in this case it's not necessary as it is enforced by
the foreign key constraint) or make the update (though the delete will
remove the record, so the update has no effect)
HtmlUnit button click
HtmlUnit button click
I'm trying to send a message on www.meetme.com but can't figure out how to
do it. I can type in the message in the comment area but clicking the Send
button doesn't do anything. What am I doing wrong? When I login and press
the Login button the page does change and everything is fine. Anyone have
any ideas or clues?
HtmlPage htmlPage = null;
HtmlElement htmlElement;
WebClient webClient = null;
HtmlButton htmlButton;
HtmlForm htmlForm;
try{
// Create and initialize WebClient object
webClient = new WebClient(BrowserVersion.FIREFOX_17 );
webClient.setCssEnabled(false);
webClient.setJavaScriptEnabled(false);
webClient.setThrowExceptionOnFailingStatusCode(false);
webClient.setThrowExceptionOnScriptError(false);
webClient.getOptions().setThrowExceptionOnScriptError(false);
webClient.getOptions().setUseInsecureSSL(true);
webClient.getCookieManager().setCookiesEnabled(true);
/*webClient.setRefreshHandler(new RefreshHandler() {
public void handleRefresh(Page page, URL url, int arg) throws
IOException {
System.out.println("handleRefresh");
}
});*/
htmlPage = webClient.getPage("http://www.meetme.com");
htmlForm =
htmlPage.getFirstByXPath("//form[@action='https://ssl.meetme.com/login']");
htmlForm.getInputByName("username").setValueAttribute("blah@gmail.com");
htmlForm.getInputByName("password").setValueAttribute("blah");
//Signing in
htmlButton = htmlForm.getElementById("login_form_submit");
htmlPage = (HtmlPage) htmlButton.click();
htmlPage =
webClient.getPage("http://www.meetme.com/member/1234567890");
System.out.println("BEFORE CLICK");
System.out.println(htmlPage.asText());
//type message in text area
HtmlTextArea commentArea =
(HtmlTextArea)htmlPage.getFirstByXPath("//textarea[@id='profileQMBody']");
commentArea.setText("Testing");
htmlButton = (HtmlButton)
htmlPage.getHtmlElementById("profileQMSend");
htmlPage = (HtmlPage)htmlButton.click();
webClient.waitForBackgroundJavaScript(7000);
//The print is exactly the same as the BEFORE CLICK print
System.out.println("AFTER CLICK");
System.out.println(htmlPage.asText());
}catch(ElementNotFoundException e){
e.printStackTrace();
}catch(Exception e){
e.printStackTrace();
}
I'm trying to send a message on www.meetme.com but can't figure out how to
do it. I can type in the message in the comment area but clicking the Send
button doesn't do anything. What am I doing wrong? When I login and press
the Login button the page does change and everything is fine. Anyone have
any ideas or clues?
HtmlPage htmlPage = null;
HtmlElement htmlElement;
WebClient webClient = null;
HtmlButton htmlButton;
HtmlForm htmlForm;
try{
// Create and initialize WebClient object
webClient = new WebClient(BrowserVersion.FIREFOX_17 );
webClient.setCssEnabled(false);
webClient.setJavaScriptEnabled(false);
webClient.setThrowExceptionOnFailingStatusCode(false);
webClient.setThrowExceptionOnScriptError(false);
webClient.getOptions().setThrowExceptionOnScriptError(false);
webClient.getOptions().setUseInsecureSSL(true);
webClient.getCookieManager().setCookiesEnabled(true);
/*webClient.setRefreshHandler(new RefreshHandler() {
public void handleRefresh(Page page, URL url, int arg) throws
IOException {
System.out.println("handleRefresh");
}
});*/
htmlPage = webClient.getPage("http://www.meetme.com");
htmlForm =
htmlPage.getFirstByXPath("//form[@action='https://ssl.meetme.com/login']");
htmlForm.getInputByName("username").setValueAttribute("blah@gmail.com");
htmlForm.getInputByName("password").setValueAttribute("blah");
//Signing in
htmlButton = htmlForm.getElementById("login_form_submit");
htmlPage = (HtmlPage) htmlButton.click();
htmlPage =
webClient.getPage("http://www.meetme.com/member/1234567890");
System.out.println("BEFORE CLICK");
System.out.println(htmlPage.asText());
//type message in text area
HtmlTextArea commentArea =
(HtmlTextArea)htmlPage.getFirstByXPath("//textarea[@id='profileQMBody']");
commentArea.setText("Testing");
htmlButton = (HtmlButton)
htmlPage.getHtmlElementById("profileQMSend");
htmlPage = (HtmlPage)htmlButton.click();
webClient.waitForBackgroundJavaScript(7000);
//The print is exactly the same as the BEFORE CLICK print
System.out.println("AFTER CLICK");
System.out.println(htmlPage.asText());
}catch(ElementNotFoundException e){
e.printStackTrace();
}catch(Exception e){
e.printStackTrace();
}
Subscribe to:
Posts (Atom)