Thursday, 3 October 2013

Why I should define a JLabel before a addActionListener?

Why I should define a JLabel before a addActionListener?

I have one JLabel and one JButton into JFrame. I write code for
actionPerformed event of JButton like following:
btnOK.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
lblA.setText("Hello"); // error here
}
});
final JLabel lblA = new JLabel("");
but i get following error:
lblA cannot be resolved
however if I placed define of JLabel before addActionListener like
following my problem solved:
final JLabel lblA = new JLabel("");
btnOK.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
lblA.setText("Hello"); // error here
}
});

Wednesday, 2 October 2013

Create class that reads in two names and outputs

Create class that reads in two names and outputs

Create a new program Reverse.java by creating a new class that reads in
two names and outputs them in reverse order. You will need two String
variables name0 and name1 and you will need to use two input dialog boxes.
Don't forget to add a space between the names in the output.
how can i do this?
ThX

Get value with jsoup from webpage

Get value with jsoup from webpage

I am new with Jsoup Current i want to get value of option but i can not.
Here is source of html page:
<div class="entrypost">
Xem nhanh:
<select onchange="window.location.href=this.value;">
<option
value="http://truyenhay.vn/kim-chi-va-cu-cai-phan-1.html"
selected="selected"> Kim chi và c&#7911; c&#7843;i ph&#7847;n
1</option>
<option
value="http://truyenhay.vn/kim-chi-va-cu-cai-phan-2.html"
>Kim chi và c&#7911; c&#7843;i
ph&#7847;n 2</option>
<option
value="http://truyenhay.vn/kim-chi-va-cu-cai-phan-3.html"
>Kim chi và c&#7911; c&#7843;i
ph&#7847;n 3</option>
<option
value="http://truyenhay.vn/kim-chi-va-cu-cai-phan-4.html"
>Kim chi và c&#7911; c&#7843;i
ph&#7847;n 4</option>
<option
value="http://truyenhay.vn/kim-chi-va-cu-cai-phan-5.html"
>Kim chi và c&#7911; c&#7843;i
ph&#7847;n 5</option>
<option
value="http://truyenhay.vn/kim-chi-va-cu-cai-phan-6.html"
>Kim chi và c&#7911; c&#7843;i
ph&#7847;n 6</option>
<option
value="http://truyenhay.vn/kim-chi-va-cu-cai-phan-7.html"
>Kim chi và c&#7911; c&#7843;i
ph&#7847;n 7</option>
<option
value="http://truyenhay.vn/kim-chi-va-cu-cai-phan-8.html"
>Kim chi và c&#7911; c&#7843;i
ph&#7847;n 8</option>
<option
value="http://truyenhay.vn/kim-chi-va-cu-cai-phan-9.html"
>Kim chi và c&#7911; c&#7843;i
ph&#7847;n 9</option>
<option
value="http://truyenhay.vn/kim-chi-va-cu-cai-phan-10.html"
>Kim Chi và C&#7911; C&#7843;i
Ph&#7847;n 10</option>
<option
value="http://truyenhay.vn/kim-chi-va-cu-cai-phan-11.html"
>Kim Chi và C&#7911; C&#7843;i
Ph&#7847;n 11</option>
<option
value="http://truyenhay.vn/kim-chi-va-cu-cai-phan-12.html"
>Kim Chi và C&#7911; C&#7843;i
Ph&#7847;n 12</option>
<option
value="http://truyenhay.vn/kim-chi-va-cu-cai-phan-13.html"
>Kim Chi và C&#7911; C&#7843;i
Ph&#7847;n 13</option>
<option
value="http://truyenhay.vn/kim-chi-va-cu-cai-phan-14.html"
>Kim Chi và C&#7911; C&#7843;i
Ph&#7847;n 14</option>
<option
value="http://truyenhay.vn/kim-chi-va-cu-cai-phan-15.html"
>Kim Chi và C&#7911; C&#7843;i
Ph&#7847;n 15</option>
<option
value="http://truyenhay.vn/kim-chi-va-cu-cai-phan-16.html"
>Kim Chi và C&#7911; C&#7843;i
Ph&#7847;n 16</option>
<option
value="http://truyenhay.vn/kim-chi-va-cu-cai-phan-17.html"
>Kim Chi và C&#7911; C&#7843;i
Ph&#7847;n 17</option>
<option
value="http://truyenhay.vn/kim-chi-va-cu-cai-phan-18.html"
>Kim Chi và C&#7911; C&#7843;i
Ph&#7847;n 18</option>
<option
value="http://truyenhay.vn/kim-chi-va-cu-cai-phan-19.html"
>Kim Chi và C&#7911; C&#7843;i
Ph&#7847;n 19</option>
<option
value="http://truyenhay.vn/kim-chi-va-cu-cai-phan-20.html"
>Kim Chi và C&#7911; C&#7843;i
Ph&#7847;n 20</option>
<option
value="http://truyenhay.vn/kim-chi-va-cu-cai-phan-21.html"
>Kim Chi và C&#7911; C&#7843;i
Ph&#7847;n 21</option>
<option
value="http://truyenhay.vn/kim-chi-va-cu-cai-phan-22.html"
>Kim Chi và C&#7911; C&#7843;i
Ph&#7847;n 22</option>
<option
value="http://truyenhay.vn/kim-chi-va-cu-cai-phan-23.html"
>Kim Chi và C&#7911; C&#7843;i
Ph&#7847;n 23</option>
<option
value="http://truyenhay.vn/kim-chi-va-cu-cai-phan-24.html"
>Kim Chi và C&#7911; C&#7843;i
Ph&#7847;n 24</option>
<option
value="http://truyenhay.vn/kim-chi-va-cu-cai-phan-25.html"
>Kim Chi và C&#7911; C&#7843;i
Ph&#7847;n 25</option>
Here is my code: Document doc =
Jsoup.parse("http://truyenhay.vn/kim-chi-va-cu-cai-phan-1.html");
// get all link
Elements elements1 = doc.select("option[value]");
Elements elements2 = elements1.select("value");
System.out.println("DDDDDDD " +elements1.size());
please help me if you can thanks a lot!

HTTP status error

HTTP status error

I am using Eclipse Kepler wit Tom cat 7.0.12. I created a dynamic web
project consisting of a jsp named as index.jsp and it was working fine
before i renamed the index.jsp as oldindex.jsp and created one another
index.jsp. however since than I am in problem. each time i run my web
application within the eclipse using run at server i received following
error: HTTP status 404 /(name of folder of my created web project) type
status report description the requested resource (/my web project folder
name) is not available. I have created a new project from scratch even
than it returns same. than i delete the tom server and created new server
within the eclipse and created a new web dynamic project. however it did
n't work either. I can see the inside the eclipse the tomcat server is
running. any help as i have spent two days without any luck.

Tuesday, 1 October 2013

horizontal layout Website like Myspace.com

horizontal layout Website like Myspace.com

I want to develop a horizontal layout Website like Myspace.com but for
each picture when you click on it, it does not go to another page but goes
to another section of this page ( it must be one page website)I need
advise for hoe i can handle that with css Html and jQuery ? I tried this
code :
<div id="menu">
<ul>
<li><a href="#home">Home</a>
</li>
<li><a href="#box1">History</a>
</li>
<li><a href="#box2">gallery</a>
</li>
</ul>
</div>
<div id="container">
<div id="header">
<h1>Burnham Beeches</h1>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut
eget eros libero. Fusce tempus quam sit amet erat mollis a
fermentum nibh imperdiet. Fusce iaculis sapien in turpis aliquet
porta. Donec tincidunt gravida tortor, vel dignissim augue
convallis sit amet. Aliquam auctor ornare accumsan.</p>
</div>
<div id="box1" class="box">
<h2><a name="box1">History</a></h2>
<img src="images/burnham-beeches-history-fullpage.jpg" />
</div>
<div id="box2" class="box">
<h2><a name="box2">Second Box</a></h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut
eget eros libero. Fusce tempus quam sit amet erat mollis a
fermentum nibh imperdiet. Fusce iaculis sapien in turpis aliquet
porta. Donec tincidunt gravida tortor, vel dignissim augue
convallis sit amet. Aliquam auctor ornare accumsan. Cras convallis
elit tincidunt arcu semper egestas. Mauris interdum fringilla
nisi. Cras a dapibus lectus. Praesent blandit ullamcorper ornare.
Nam hendrerit sollicitudin urna non ultricies. Phasellus
condimentum auctor risus, at accumsan tellus tempor vel. Nunc
mattis eleifend dolor at adipiscing.</p>
</div>
</div>
but ineed to have pictures not text

Injecting html snippet with JQuery into existing html page

Injecting html snippet with JQuery into existing html page

I want to inject certain html snippet with JQuery into existing html page.
Existing snippet:
<table class="course hoverHighlight">
<tbody>...</tbody>
...
</table>
I want to inject:
<thead>
<tr>
<th class="title">Course</th>
<th class="author">Author</th>
<th class="level">Level</th>
<th class="rating">Rating</th>
<th class="duration">Duration</th>
<th class="releaseDate">Released</th>
</tr>
</thead>
before tbody tag.
<table class="course hoverHighlight">
<thead>...</thead>
<tbody>...</tbody>
</table>
I have tried this code but it didn`t work:
function() {
var theadInjection= $("<thead>
<tr>
<th class="title">course</th>
<th class="author">author</th>
<th class="level">level</th>
<th class="rating">rating</th>
<th class="duration">duration</th>
<th class="releasedate">released</th>
</tr>
</thead>");
$( '.course' ).prepend(theadInjection);
}
Simple injection like this one did work:
function() {
var theadInjection= $("<thead></thead>");
$( '.course' ).prepend(theadInjection);
Thanks.

Passing PCI Scan on apache 2.2.22

Passing PCI Scan on apache 2.2.22

We are on Ubuntu 12.04 and apache 2.2.2 version. We had PCI scan done on
our site and 2 vulnerabilities came out that we can not get under control.
First one is BEAST attack and other one SSL RC4 Cipher Suites Supported.
So far I have tried following that looks promising. I tried with few more
changes after searching for help, but those changes in turn started
breaking browsers and were discarded.
SSLProtocol -SSLv2 -TLSv1 +SSLv3
SSLHonorCipherOrder On
SSLCipherSuite
ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-RC4-SHA:ECDHE-RSA-RC4-SHA:ECDH-ECDSA-RC4-SHA:ECDH-RSA-RC4-SHA:ECDHE-RSA-AES256-SHA:RC4-SHA:!MD5:!aNULL:!EDH
SSLCompression off
or
SSLProtocol ALL -SSLv2
SSLHonorCipherOrder On
SSLCipherSuite
ECDH+AESGCM:DH+AESGCM:ECDH+AES256:DH+AES256:ECDH+AES128:DH+AES:ECDH+3DES:DH+3DES:RSA+AES:RSA+3DES:!ADH:!AECDH:!MD5:!DSS
SSLCompression off
Based on scan results on ssllabs, I am able to get only one of the
vulnerability mitigated. What changes I need to do so that both
vulnerabilities are addressed and does support current version of
browsers?

Can I change notification dialog text?

Can I change notification dialog text?

I am using the latest Xubuntu 13.04. When I go to shut down, I receive the
confirmation notification stating "Are you sure you want to shut down?" I
would like to keep this dialog box, but I want to customize the message it
displays. Can this be done?

Monday, 30 September 2013

Disable Password Authentication for Remote Users Only

Disable Password Authentication for Remote Users Only

I've read how it is possible to disable password authentication on an
Ubuntu server. However, is it possible to disable this for remote users
only?
I'm afraid that, if I enable this both locally and remotely (as designed),
I will ultimately lose the key and lock myself out (over time). If I were
able to disable password authentication for remote users only, losing the
key wouldn't be so tragic; I could simply go to the LAN and login with a
password and create a new key.

Wanting an explanation to the solution method of the system of differential equations.

Wanting an explanation to the solution method of the system of
differential equations.

Please can anybody help me with explaining, in detail, why and how the
author solves the system of differential equations by such a step (see
below)? How the equation 6.3 is formed step by step? Why such a column
basis is valid? It would be extremely helpful if someone knows the name of
the method or could give an exemplification.

ngResource retrive unique ID from POST response after $save()

ngResource retrive unique ID from POST response after $save()

So I have a Resource defined as follows:
angular.module('questionService', ['ngResource'])
.factory('QuestionService', function($http, $resource) {
var QuestionService = $resource('/api/questions/:key', {}, {
query: {
method:'GET',
isArray:true,
},
save: {
method: 'POST',
}
});
return QuestionService
});
And later on I take some form input and do the following
var newQ = {
txt: $scope.addTxt
};
QuestionService.save(newQ)
The server responds to the POST request both by reissuing the JSON for the
object and setting the location header with the new unique ID. The problem
is that Angular is not saving that returned JSON or the location header
into the object and it is not getting set with the ID from the server for
future operations. I've tried a number of things such as:
transformResponse: function(data, headersGetter) {
locationHeader = headersGetter().location;
key = locationHeader.split('/').slice(-1)[0];
data.key = key;
return data;
}
However the returned data item doesn't seem to be getting used. Am I
missing something? This seems like a pretty common use case for
interacting with a REST api.
Thanks!

Using nested if statements to structure code

Using nested if statements to structure code

I'm trying to structure my code in a readable way. I've read that one way
of doing it is as follows:
if(Init1() == TRUE)
{
if(Init2() == TRUE)
{
if(Init3() == TRUE)
{
...
Free3();
}
Free2();
}
Free(1);
}
I like this way of doing things, because it keeps each FreeX inside its
matching InitX loop, but if the nesting goes beyond three levels it
quickly becomes unreadable and goes way beyond 80 columns. Many functions
can be broken up into multiple functions so that this doesn't happen, but
it seems dumb to break up a function just to avoid too many levels of
nesting. In particular, consider a function that does the initialization
for a whole class, where that initialization requires ten or more function
calls. That's ten or more levels of nesting.
I'm sure I'm overthinking this, but is there something fundamental I'm
missing in the above? Can deep nesting be done in a readable way? Or else
restructured somehow whilst keeping each FreeX inside its own InitX loop?
By the way, I realise that the above code can be compacted to if(Init1()
&& Init2()..., but the code is just an example. There would be other code
between each InitX call that would prevent such a compaction.

Sunday, 29 September 2013

Implementing IFB_LLLLCHAR

Implementing IFB_LLLLCHAR

We are using jpos server with ASCIChannel and custom package which
contains one field with max length 9999 to do this we implemented
IFB_LLLLCHAR as follow
public class IFB_LLLLCHAR extends ISOStringFieldPackager {
public IFB_LLLLCHAR() {
super(NullPadder.INSTANCE, AsciiInterpreter.INSTANCE,
BcdPrefixer.LLLL);
}
public IFB_LLLLCHAR(int len, String description) {
super(len, description, NullPadder.INSTANCE,
AsciiInterpreter.INSTANCE, BcdPrefixer.LLLL);
checkLength(len, 9999);
}
public void setLength(int len)
{
checkLength(len, 9999);
super.setLength(len);
}
}
Problem is that i couldn't use the whole 9999 because if the size of whole
message goes over 9999 it throws following exception while sending it
<exception name="len exceeded">
java.io.IOException: len exceeded
at
org.jpos.iso.channel.ASCIIChannel.sendMessageLength(ASCIIChannel.java:80)
at org.jpos.iso.BaseChannel.send(BaseChannel.java:528)
at
com.advam.gateway.terminalmanagementserver.gateway.LogUploadFuncTest.testLogUpload(LogUploadFuncTest.java:39)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at
org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:130)
at
org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
</exception>
Can anybody tell me why i am getting this exception and how to fix it.
Kindly keep in mind while answering that I don't have much knowledge about
inside of jpos. Thanks

triangle numbers in java

triangle numbers in java

I am new to Java and now I want to learn better for loop. I made some
examples , but I don't know how to do a triangle that look like this: for
n=6:
111111
22222
3333
222
11
6
My code until now:
class Pyramid
{
public static void main (String[] args)
{
int i,n=9,j;
for(i=n;i>=1;i--)
{
for(j=1;j<=i;j++) {
System.out.print(i); }
System.out.print("\n");
}}}
But what I managed to do it looks like this:
666666
55555
4444
333
22
1
How to make it in reverse order and to print the given number n when just
one character has to be print?

Airspeed conversion in Matlab

Airspeed conversion in Matlab

I am trying to convert True Airspeed (TAS) to Calibrated Airspeed (CAS) in
MATLAB using the function "correctairspeed", but it gives me an error
because my speeds are in the supersonic regime.
I can always use the formulae to convert the speed but I was wondering if
there is an easier way to do it, since I have a bunch of different speeds
(supersonic as well as subsonic). Something like "correctairspeed" for
super-sonic would be really helpful.
Any ideas?

Saturday, 28 September 2013

Cannot evaluate script arguments from function

Cannot evaluate script arguments from function

I've started writing shell scripts again and I've found myself in a
situation where I frequently have to write debug echo's to trace what the
script is doing. The, easy, way I used to do this right was to write
something like this :
#!/bin/bash
myVar = 'Erractic Nonesense'
echo "myVar: $myVar"
==> myVar: Erractic Nonesense
This worked great and was fairly simple but, having to write this for
every variable I wished to trace was tiring and as a person who thinks
that having less code to do more stuff is great, I wrote myself a
function:
#!/bin/bash
function dbg # $msg
{
echo "$@: ${!@}"
}
myVar = 'Erractic Nonesense'
dbg myVar
==> myVar: Erractic Nonesense
This works great for regular variables but, for the scripts arguments ($1,
$2, etc.), does not work. Why?
==> $ ./myScript 123
#!/bin/bash
...
dbg 1 # This is the bugger in question.
==> 1: 1

Python3, Gtk3 - GtkGrid expanding

Python3, Gtk3 - GtkGrid expanding

A GtkWindow containing a GtkGrid containing some GtkLabels won't expand
when the window is grown. I want the grid to expand horizontally.
grid.set_hexpand(True) #No result
grid.expand = True #No result
The GtkLabel in the rightmost column is set to align right so I can
accurately see if it's being expanded or not:
label.set_halign(Gtk.Align.END)
Am I misunderstanding how a grid works? (A GtkTable had a set amount of
columns, perhaps the GtkGrid doesn't and relies on it's sub elements being
set to expand?)

New Sequence Points in C++11

New Sequence Points in C++11

With the new college year upon us.
We have started to receive the standard why does ++ i ++ not work as
expected questions.
After just answering one of these type of questions I was told that the
new C++11 standard has changed and this is no longer undefined behavior. I
have heard that sequence points have been replaced by sequenced before and
sequenced after but have not read deep (or at all) into the subject.
So the question I was just answering had:
k = ++ (++ i);
So the question is:
How has the sequence points changes in C++11 and how does it affect
questions like the above. Is it still undefined behavior or is this now
well defined?

How to make JFrame wait for input before the user can proceed?

How to make JFrame wait for input before the user can proceed?

I'm making a question and answer game. The user must first pick a category
in a JFrame then another Jframe would pop up with the question. What i
want is to prevent the user from choosing another category without first
answering the question.

Friday, 27 September 2013

How can you tell an Asset Catalog (.xcassets) to use the same image for multiple settings?

How can you tell an Asset Catalog (.xcassets) to use the same image for
multiple settings?

We have several Xcode app projects, and we're upgrading all of them to use
the latest Xcode 5 features, including Asset Catalogs (.xcassets).
All of our default (launch) images already include spacing for the status
bar, and we want to use these images for both the iOS 5,6 and iOS 7 launch
images. Further, we don't want to include multiple copies of these images.
One of our projects is correctly set to use the same image for both of
these sets. However, this was setup more so by accident.
Besides editing the Contents.json file directly (which, I suppose, is a
workaround if need be), how can we do this using the Xcode GUI editor for
Asset Catalog?
What we've already tried
1) Dragging and dropping the file to a different position... just moves
the image to the other set
2) Dragging and dropping the same file from Finder to the Asset Catalog...
creates a new copy of the image