|
Run this Code
package p1;
import java.io.IOException;
public class perfect
{
public static void main(String[] args) throws IOException
{
int stnumber = 1;
int ennumber = 10000;
System.out.println("Perfect Numbers between "+stnumber+ " and "+ennumber);
for (int i = stnumber; i <= ennumber; i++)
{
int number = i;
int sqrt = (int) Math.sqrt(number);
if (sqrt * sqrt == number)
{
System.out.println(number+ " = "+sqrt+"*"+sqrt);
}
}
}
}
|
|
|
|
|
Is it possible to scroll JFrame if so den how?
|
|
|
|
|
|
I m not able to add the external jar into classpath....can u plz help me....
error-Could not write file: .classpath.
|
|
|
|
|
Classpath is not a file it is a parameter specification to the javac or java commands. What exactly are you trying to do?
|
|
|
|
|
1) Integer currentGroupId = Integer.valueOf(-1);
2) currentGroupId = Integer.valueOf(rs.getInt("CONSUMER_GROUP_ID"));
Please explain both of it
|
|
|
|
|
Please post your question once only. Also, you can refer to the documentation[^] for basic questions.
|
|
|
|
|
1) Integer currentGroupId = Integer.valueOf(-1);
2) currentGroupId = Integer.valueOf(rs.getInt("CONSUMER_GROUP_ID"));
Please explain both of it
|
|
|
|
|
private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {
filepath ="/home/GUI/Language_Independent/Output/Frame_1.txt";
file =new File(filepath);
fileContents="";
try
{
br = new BufferedReader(new FileReader(filepath));
}
catch(Exception E)
{
jLabel1.setText(E.toString());
}
try
{
while((fileContents= br.readLine())!=null)
{
System.out.println("fileContents");
jLabel1.setText(fileContents);
String str = "a";
while(br.readLine()== str) {
jLabel1.setForeground(Color.red);
}
}
br.close();
}
catch(Exception E1)
{
jLabel1.setText(E1.toString());
}
}
Frame_1 consist of generate text eg:abcdefgh..
for this generated file i want to set color for specific char eg a=red so on.
jLabel1.setForeground(Color.red);
is not working at all.Please someone suggest and thnks in advanced
|
|
|
|
|
Your test in the sub loop probably never yields true. Have you stepped through your code with the debugger?
|
|
|
|
|
ya i also observed it is not going inside the loop condition is not satisfied but i can solved it out is my logic wrong ?
|
|
|
|
|
Your logic does not make much sense. You read a line from the file, then you are trying to use a while loop to read another line of text and compare it with the string a . You should read a line and then test if it contains the character you are looking for. However, note that you cannot set different characters to different colours. You can only use a single colour for the entire label.
|
|
|
|
|
i want to display a word file into my application.
It is like extracting the text to put in JTextArea.
Help what best API can use?
an easy to understand!
|
|
|
|
|
|
Quote: how to display panel just below input panel.?
|
|
|
|
|
|
Chinese
|
|
|
|
|
What does this mean, and what have you tried?
|
|
|
|
|
Actually I have two Jpanel. One JPanel which takes input and the result is to be display in another JPanel.I just want that output Jpanel to be display just below the input JPanel.
|
|
|
|
|
|
<blockquote class="quote"><div class="op">Quote:</div>
package Speech.WavePanel;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
import javax.swing.JFrame;
import javax.swing.JScrollBar;
import javax.swing.JScrollPane;
import javax.swing.SwingUtilities;
public class output extends javax.swing.JFrame {
String filepath;
String fileContents;
File file;
BufferedReader br;
public output() {
initComponents();
}
private void ScreenProperties()
{
jLabel1.setSize(new Dimension(800, 150));
jLabel1.setPreferredSize(new Dimension(800, 150));
JFrame frame= new JFrame();
frame.setLocation(1650, 430);
JScrollPane scrollPane = new JScrollPane(jLabel1);
add(scrollPane, BorderLayout.CENTER);
scrollPane = new JScrollPane();
scrollPane.getViewport().add( jLabel1 );
}
@SuppressWarnings("unchecked")
private void initComponents() {
jScrollPane1 = new javax.swing.JScrollPane();
jPanel1 = new javax.swing.JPanel();
jPanel2 = new javax.swing.JPanel();
jScrollPane3 = new javax.swing.JScrollPane();
jLabel1 = new javax.swing.JLabel();
jButton4 = new javax.swing.JButton();
jButton3 = new javax.swing.JButton();
jButton2 = new javax.swing.JButton();
jButton1 = new javax.swing.JButton();
jSeparator1 = new javax.swing.JSeparator();
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 100, Short.MAX_VALUE)
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGap(0, 100, Short.MAX_VALUE)
);
setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
jScrollPane3.setHorizontalScrollBarPolicy(javax.swing.ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
jScrollPane3.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);
jScrollPane3.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
jScrollPane3.setDebugGraphicsOptions(javax.swing.DebugGraphics.NONE_OPTION);
jLabel1.setForeground(java.awt.Color.black);
jLabel1.setText("jLabel1");
jScrollPane3.setViewportView(jLabel1);
jButton4.setText("output_frame4");
jButton4.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
jButton4MouseClicked(evt);
}
});
jButton4.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton4ActionPerformed(evt);
}
});
jButton3.setText("output_frame3");
jButton3.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
jButton3MouseClicked(evt);
}
});
jButton3.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton3ActionPerformed(evt);
}
});
jButton2.setText("output_frame2");
jButton2.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
jButton2MouseClicked(evt);
}
});
jButton1.setText("output_frame1");
jButton1.addMouseListener(new java.awt.event.MouseAdapter() {
public void mouseClicked(java.awt.event.MouseEvent evt) {
jButton1MouseClicked(evt);
}
});
javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
jPanel2.setLayout(jPanel2Layout);
jPanel2Layout.setHorizontalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jSeparator1, javax.swing.GroupLayout.Alignment.TRAILING)
.addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 670, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(jPanel2Layout.createSequentialGroup()
.addComponent(jButton1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton2)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jButton3)
.addGap(18, 18, 18)
.addComponent(jButton4)))
.addContainerGap())
);
jPanel2Layout.setVerticalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel2Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
.addComponent(jButton1)
.addComponent(jButton2)
.addComponent(jButton3)
.addComponent(jButton4))
.addGap(9, 9, 9)
.addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 83, javax.swing.GroupLayout.PREFERRED_SIZE)
.addContainerGap())
);
javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jPanel2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(0, 12, Short.MAX_VALUE))
);
pack();
}
private void jButton1MouseClicked(java.awt.event.MouseEvent evt) {
setTitle(" OUTPUT PANEL ");
setBackground(Color.white);
setVisible(true);
filepath ="/home/GUI/Language_Independent/Output/Frame_1.txt";
file = new File(filepath);
fileContents="";
try{
br = new BufferedReader ( new FileReader ( filepath ) ) ;
}
catch(Exception E){
jLabel1.setText(E.toString());
}
try{
while ((fileContents = br.readLine()) != null) {
System.out.println (fileContents) ;
jLabel1.setText(fileContents);
}
br.close();
}
catch(Exception E2){
jLabel1.setText(E2.toString());
}
}
private void jButton2MouseClicked(java.awt.event.MouseEvent evt) {
setBackground(Color.WHITE);
setVisible(true);
filepath="/home/GUI/Language_Independent/Output/Frame_2.txt";
file=new File(filepath);
fileContents="";
try
{
br = new BufferedReader(new FileReader(filepath));
}
catch(Exception E)
{
jLabel1.setText(E.toString());
}
try
{
while((fileContents= br.readLine())!=null)
{
System.out.println("fileContents");
jLabel1.setText(fileContents);
}
br.close();
}
catch(Exception E1)
{
jLabel1.setText(E1.toString());
}
}
private void jButton3MouseClicked(java.awt.event.MouseEvent evt) {
}
private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {
filepath ="/home/GUI/Language_Independent/Output/Frame_4.txt";
file =new File(filepath);
fileContents="";
try
{
br = new BufferedReader(new FileReader(filepath));
}
catch(Exception E)
{
jLabel1.setText(E.toString());
}
try
{
while((fileContents= br.readLine())!=null)
{
System.out.println("fileContents");
jLabel1.setText(fileContents);
}
br.close();
}
catch(Exception E1)
{
jLabel1.setText(E1.toString());
}
}
private void jButton4MouseClicked(java.awt.event.MouseEvent evt) {
filepath="";
file= new File(filepath);
fileContents="";
try
{
br= new BufferedReader(new FileReader(filepath));
}
catch(Exception E)
{
jLabel1.setText(E.toString());
}
try
{
while((fileContents= br.readLine())!=null)
{
System.out.println("fileContents");
jLabel1.setText(fileContents);
}
br.close();
}
catch(Exception E1)
{
jLabel1.setText(E1.toString());
}
}
private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {
filepath="";
file = new File(filepath);
fileContents ="";
}
public static void main(String args[]) {
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(output.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(output.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(output.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(output.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
SwingUtilities.invokeLater(new Runnable(){
public void run() {
new output().setVisible(true);
JScrollPane pn= new JScrollPane();
pn.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
pn.getVerticalScrollBar().setUnitIncrement(10);
pn.setVisible(true);
}
});
}
private javax.swing.JButton jButton1;
private javax.swing.JButton jButton2;
private javax.swing.JButton jButton3;
private javax.swing.JButton jButton4;
private javax.swing.JLabel jLabel1;
private javax.swing.JPanel jPanel1;
private javax.swing.JPanel jPanel2;
private javax.swing.JScrollPane jScrollPane1;
private javax.swing.JScrollPane jScrollPane3;
private javax.swing.JSeparator jSeparator1;
}
</blockquote>
This is the output file which I want it to display just below my input panel when actionlistener is performed at input panel .actually to make it do i need to create the output panel inside the frame which contained input panel itself? thanks in advance..
|
|
|
|
|
0 down vote favorite
on my ubuntu terminal i was trying to compile and run the program like this
javac -cp "/usr/lib/jvm/jdk1.8.0_20/lib/gs-core-1.2.jar" GraphExplore.java
successfully compiled.now to run
java -cp "/usr/lib/jvm/jdk1.8.0_20/lib/gs-core-1.2.jar" GraphExplore
I got error saying
Error: Could not find or load main class GraphExplore
I am newbee in java.please someone help me to resovle this issue.thanks in advance.what i tried to resolve this error.i kept .class file in one folder and run i mean i kept in one path and tried to execute in that path only but it didnt work.please help me
|
|
|
|
|
You need to show us where, in your program, the main method is.
|
|
|
|
|
import org.graphstream.graph.*;
import org.graphstream.graph.implementations.*;
import java.util.Iterator;
public class GraphExplore {
public static void main(String args[]) {
new GraphExplore();
}
public GraphExplore() {
Graph graph = new SingleGraph("tutorial 1");
graph.addAttribute("ui.stylesheet", styleSheet);
graph.setAutoCreate(true);
graph.setStrict(false);
graph.display();
graph.addEdge("AB", "A", "B");
graph.addEdge("BC", "B", "C");
graph.addEdge("CA", "C", "A");
graph.addEdge("AD", "A", "D");
graph.addEdge("DE", "D", "E");
graph.addEdge("DF", "D", "F");
graph.addEdge("EF", "E", "F");
for (Node node : graph) {
node.addAttribute("ui.label", node.getId());
}
explore(graph.getNode("A"));
}
public void explore(Node source) {
Iterator<? extends Node> k = source.getBreadthFirstIterator();
while (k.hasNext()) {
Node next = k.next();
next.setAttribute("ui.class", "marked");
sleep();
}
}
protected void sleep() {
try { Thread.sleep(1000); } catch (Exception e) {}
}
protected String styleSheet =
"node {" +
" fill-color: black;" +
"}" +
"node.marked {" +
" fill-color: red;" +
"}";
}
|
|
|
|
|
Strange, I cannot see anything wrong with your code. Are you sure that the compilation worked successfully and the class file exists in the directory where you are calling the java command from?
|
|
|
|