Official Programmers Thread

  • Christian Chat is a moderated online Christian community allowing Christians around the world to fellowship with each other in real time chat via webcam, voice, and text, with the Christian Chat app. You can also start or participate in a Bible-based discussion here in the Christian Chat Forums, where members can also share with each other their own videos, pictures, or favorite Christian music.

    If you are a Christian and need encouragement and fellowship, we're here for you! If you are not a Christian but interested in knowing more about Jesus our Lord, you're also welcome! Want to know what the Bible says, and how you can apply it to your life? Join us!

    To make new Christian friends now around the world, click here to join Christian Chat.
E

ex-Ranger

Guest
im currently teaching myself Java and ive hit a roadblock i need a GUI for the program im writing. would any one happen to know where i can find a online tutorial for programing a GUI using eclipse
 
W

wwjd_kilden

Guest
if you got any specific questions ask :) I only know a bit, but I have used Eclipse when programming java, and made some GUI's

Trail: Creating a GUI With JFC/Swing (The Java™ Tutorials)

how much do you know? (like, do you know how to use JFrame, JPane, different layoutl etc? )

if you are at the basics, start making one file that extends JFrame, and one that extends JPanel that you add to the one extending JFrame and remember to set the visibility and size of both.
 
Last edited:
E

ex-Ranger

Guest
if you got any specific questions ask :) I only know a bit, but I have used Eclipse when programming java, and made some GUI's

Trail: Creating a GUI With JFC/Swing (The Java™ Tutorials)

how much do you know? (like, do you know how to use JFrame, JPane, different layoutl etc? )

if you are at the basics, start making one file that extends JFrame, and one that extends JPanel that you add to the one extending JFrame and remember to set the visibility and size of both.
ill post my code and it will tell you the extent of my java knowledge
this is the code for the program i mentioned
Code:
        import java.util.Scanner;
        public class mainclass {

            public static void main(String[] args) {
                Scanner calendar = new Scanner(System.in);
                System.out.println("open the calendar built into your computer and select for days in a square like 4 5 11 12 and add them together");
                System.out.println("Enter sum of all four days:");
                int sum = calendar.nextInt();
                int day, day2, day3, day4, sum1;
                sum1 = sum - 16;
                day = sum1 / 4;
                System.out.printf("first day is: ");
                System.out.println(day );
                day2 = day + 1;
                System.out.printf("second day is: ");
                System.out.println(day2 );
                day3 = day + 7;
                System.out.printf("third day is: ");
                System.out.println(day3 );
                day4 = day + 8;
                System.out.printf("forth day is: ");
                System.out.println(day4 );
            

    }

}
on a completely unrelated note would anyone know how to make adobe flash player dump its used buffer cache (example: im streaming a movie when i hit anything over 10mins adobe is using so much memory that its unwatchable and my computer suffers a thermal shutdown so i want adobe to dump the buffer that its all ready "played")
 
W

wwjd_kilden

Guest
for some reason the program I am trying to make will not run, and I cannot be bothered to find out why today :p but here is one class that might help, plus a modifications of your class:

-----

import java.awt.Component;

import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;


public class CalendarPanel extends JPanel {

public void CalendarPanel(){


JLabel instructions = new JLabel("open the calendar built into your computer and select for days in a square like 4 5 11 12 and add them together" +
"\n Enter sum of all four days ");

JTextField input = new JTextField();
add(input);

TestClass calculations = new TestClass();

calculations.calclulate();

// add metod to get results from calculations object
// and print theese to a graphical object
// for now you could use JLabels

int day = calculations.getDay();
JLabel firstday = new JLabel("Day 1" + day);

add(firstday);

}



}
--------


import java.util.Scanner;

public class TestClass {

//public static void main(String[] args) {

private int day, day2, day3, day4, sum1; // ALWAYS decalre variabeles private when possible
Scanner calendar;

public void TestClass(){
calendar = new Scanner(System.in);

}

public void calclulate(){

// System.out.println("open the calendar built into your computer and select for days in a square like 4 5 11 12 and add them together");
// System.out.println("Enter sum of all four days:");

int sum = calendar.nextInt();

sum1 = sum - 16;
day = sum1 / 4;

// Print to labels or elsewhere
System.out.printf("first day is: ");
System.out.println(day );
day2 = day + 1;
System.out.printf("second day is: ");
System.out.println(day2 );
day3 = day + 7;
System.out.printf("third day is: ");
System.out.println(day3 );
day4 = day + 8;
System.out.printf("forth day is: ");
System.out.println(day4 );


}

public int getDay(){ // Normally "getters" and "setters" are private ;)

return day;

}


}
 
W

wwjd_kilden

Guest
of course you will need to get the content from the input text area and send it to the calculations method
I'm still a rookie though, and I hate coding blind, so I cannot get any more accurate as long as my program will not run.
 
E

ex-Ranger

Guest
for some reason the program I am trying to make will not run, and I cannot be bothered to find out why today :p but here is one class that might help, plus a modifications of your class:

-----

import java.awt.Component;

import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;


public class CalendarPanel extends JPanel {

public void CalendarPanel(){


JLabel instructions = new JLabel("open the calendar built into your computer and select for days in a square like 4 5 11 12 and add them together" +
"\n Enter sum of all four days ");

JTextField input = new JTextField();
add(input);

TestClass calculations = new TestClass();

calculations.calclulate();

// add metod to get results from calculations object
// and print theese to a graphical object
// for now you could use JLabels

int day = calculations.getDay();
JLabel firstday = new JLabel("Day 1" + day);

add(firstday);

}



}
--------


import java.util.Scanner;

public class TestClass {

//public static void main(String[] args) {

private int day, day2, day3, day4, sum1; // ALWAYS decalre variabeles private when possible
Scanner calendar;

public void TestClass(){
calendar = new Scanner(System.in);

}

public void calclulate(){

// System.out.println("open the calendar built into your computer and select for days in a square like 4 5 11 12 and add them together");
// System.out.println("Enter sum of all four days:");

int sum = calendar.nextInt();

sum1 = sum - 16;
day = sum1 / 4;

// Print to labels or elsewhere
System.out.printf("first day is: ");
System.out.println(day );
day2 = day + 1;
System.out.printf("second day is: ");
System.out.println(day2 );
day3 = day + 7;
System.out.printf("third day is: ");
System.out.println(day3 );
day4 = day + 8;
System.out.printf("forth day is: ");
System.out.println(day4 );


}

public int getDay(){ // Normally "getters" and "setters" are private ;)

return day;

}


}
of course you will need to get the content from the input text area and send it to the calculations method
I'm still a rookie though, and I hate coding blind, so I cannot get any more accurate as long as my program will not run.
thanks ill attempt to use this
 
W

wwjd_kilden

Guest
Can i query for only part of data (SQL?)

So, I am making a PIM in C#for an assignment at school, but this bit I cannot wrap my head around how to solve;

I have a database named appointments where I can save text (very basic for now while I experiment)

mysql> explain appointments;
+-------+--------------+------+--
| Field | Type | Null | K
+-------+--------------+------+--
| time | datetime | YES |
| apt | varchar(100) | YES |
| place | varchar(30) | YES |
+-------+--------------+------+--

Now I have made a C# calendar where I click the day of a DateTimeCalendar, and then display a form

I want this form to show the given appointment of the chosen day....

Now as long as I ignore the hours, mins and seconds while saving the info this works fine,
(2012-03-05 00:00:00) as the defaults of these values will be 0 when I just click the date in a calendar anyway:

// selecteddate is the date selected from a MonthCalendar ( selecteddate = monthCalendar1.SelectionStart


String sqlDate = selecteddate.Year + "-" + selecteddate.Month + "-" + selecteddate.Day
+ " " + selecteddate.Hour + ":" + selecteddate.Minute + ":" + selecteddate.Second; //


// will result in the string: 05.03.2012 00:00:00


String start = "SELECT * FROM appointments ";
String condition = "WHERE time = '" + selecteddate + "'";


so if I have this already saved in my DB, and no set "clock" time, I can use a select ... where and retrive it, no problem

But, what if I now had saved a hour and minute value on each row?

How can I make my program still retrieve the datarow matching the selected day, month and year,
but ignore the fact that the data is stored with varying values for hour, min, sec?

(like: "get data from row matching 2012 March 3rd, ANY hour of day" ?)
 

JerryRice

Senior Member
Jan 16, 2011
122
0
16
I dont know c# very well but you can use a substring. Mysql even lets u fetch using substring.. sorry i dont have time to explain right now
 
W

wwjd_kilden

Guest
I think I solved the problem, it truned out the MonthCalendar will return days and months like : 1, 2, 3... while sql has it stored as 01, 02, 03 ....
I just added a wildcard to work around it. :)
 
W

wwjd_kilden

Guest
My current code ignores the time (hours, mins, secs)
String sql = "SELECT DATE_FORMAT(time, '%Y/%m/%d') AS time, apt, place FROM appointments WHERE time LIKE " + "\"" + querydate + "%" + "\"";

But it does not retrive the time either (so it outputs 2012/03/10)

Can i make it retrieve the hours and mins too, but still get me ALL results for the given date (so that I dont have to ask for every possible combination of hours)... ?


I want it to output 2012/03/10 21:30
 
W

wwjd_kilden

Guest
OK, changed that stuff

New questoion, I want to validate my xml file. The xml file itself contains a schema, made by the dataset.savexml method
How do I do this?..... (I want to detect if the file has been corrupted/ elements are missing. Later I also need to be able to change element names,
but for now I just want to be able to make sure the file is OK)

I have tried a few methods, but one seem to give validation errors even after fix the part of the code, and one claims every element is wrong...

// returns null exception error when I remove part of code in xml, but keeps throwing it when I put that bit back in
try
{ ds.ReadXml("testCalendarAppontments.xml", XmlReadMode.ReadSchema); }
catch (Exception e)
{MessageBox.Show("Feil ved lesing / Validering av XML" +e);
}

// claims everything is wrong

FileStream stream = new FileStream("testCalendarAppontments.xml", FileMode.Open);
XmlValidatingReader vr = new XmlValidatingReader(stream, XmlNodeType.Element, null);
vr.ValidationType =
ValidationType.Schema;
vr.ValidationEventHandler +=
new ValidationEventHandler(ValidationHandler);
while (vr.Read()) ;
Console.WriteLine("Validation finished: {0} validation errors", _ValidationErrorsCount);

public static void ValidationHandler(object sender, ValidationEventArgs args)
{
Console.WriteLine("***Validation error");
Console.WriteLine("\tSeverity:{0}", args.Severity);
Console.WriteLine("\tMessage :{0}", args.Message);
_ValidationErrorsCount++;
}
//====
Message :Could not find schema information for the element 'avtaler'.
Validation error
Severity:Error
Message :The 'PIMappointments' element is not declared.


//=== same error is given for all my elements even if they have not been altered


... I should point out: The ONLY thing I know about schema and validation is that it is used to determine how the structure of a xml file should do, and thus give a message if the xml part does not match what described in the schema. I do not know how to use it properly.


 
W

wwjd_kilden

Guest
^I still didnt figure out that one, not even my taeacher did

Here's some fun

[video]http://www.youtube.com/watch?v=a324ykKV-7Y[/video]
 
W

wwjd_kilden

Guest
Tech question. Despite of my edcuation, I know nothing about the tech part of computers.
- I realize this kind of stuff is difficult to answer from a distance, but here goes:

We have an old computer standing in my parents house that we are unable to make work.

When we try to boot, it goes through the list trying the onboard sata, CD-- ROM , floppy etc, failing on each.
(Primary hard disk drive 1 failure, floppy drive failure, no boot device available...)

When I entered the BIOS and viewed the boot order, the onboard SATA was listed as not present....

in the list of devices there is a Drive 0 and a Drive 2,
in the onboard devices list, there is only soundcard, videocard etc listed. (I do not know if there should be hard drives here though)

Hard drive diagnostics is able to find drive 0, and says "Error" on drive 2.

I tried disabeling drive 2 in BIOS, and booting from utility drive just to see if there was any change

now the "Not present" disappeared from the onboard SATA in the boot order list....
but it still fails to actually boot/ find the drive

From my limited understanding of the physicals parts of the computer, I believe all wires are where they should be (we never removed any between it wokring and not working, so that should not be a problem anyway),

And ideas? (Apart from "scrap it :p ")
 
W

wwjd_kilden

Guest
XSL transform

I am attempting to figure out how transforms work. Now I am able to change tag names, but apparently not to loop
(only first element appears in my transformed file). This is probably a real noob question, but I am simply unable to figure out how to fix it

XML original file

<?xml version="1.0" encoding="UTF-8"?>
<dogs dog-count="2">
<dog age="3">
<color>black</color>
<feeling>hungry</feeling>
<name>Puppy</name>
</dog>
<dog age="2">
<color>white</color>
<feeling>full</feeling>
<name>Snow</name>
</dog>
</dogs>


XML result file


<testcolor>
black
</testcolor>
<testname>
Puppy
</testnamer>
<testfeeling>
hungry
</testfeeling>

XSLT used
<?xml version="1.0" encoding="UTF-8" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:eek:utput method="text" omit-xml-declaration="yes"/>

<xsl:template match="/">
<xsl:element name="dogs">

&lt;testcolor<xsl:for-each select="dogs/dog/color"/>&gt;
<xsl:element name="MyDogs"><xsl:value-of select="dogs/dog/color"/>
&lt;/testcolor<xsl:for-each select="dogs/dog/color"/>&gt;

&lt;testname<xsl:for-each select="dogs/dog/name"/>&gt;
<xsl:element name="MyDogs"><xsl:value-of select="dogs/dog/name"/>
&lt;/testnamer<xsl:for-each select="dogs/dog/name"/>&gt;

&lt;testfeeling<xsl:for-each select="dogs/dog/feeling"/>&gt;
<xsl:element name="MyDogs"><xsl:value-of select="dogs/dog/feeling"/>
&lt;/testfeeling<xsl:for-each select="dogs/dog/feeling"/>&gt;

</xsl:element>
</xsl:element>
</xsl:element>
</xsl:element>

</xsl:template>
</xsl:stylesheet>
 
W

wwjd_kilden

Guest
I am trying to refresh my Java skills, and am playing around with simple input from the command - line.

I have a question:
How come surroning a block in "while true" makes me able to return a vale inside the block (in a method returning a int),
but does not complain that I don't have a return under "if this fails"? Shouldn't the metod still expext an int irrelevant of the "while"?

public static int readInt(String ledetekst)
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in) );
while (true)
{
System.out.print(ledetekst + ":");
try
{
return Integer.parseInt(br.readLine().trim() );
}
catch (Exception e)
{
System.out.println("Value must be integer \n");
continue;
}
}
}
 
W

wwjd_kilden

Guest
And a ASP question

How do I use a variable (like the i from the for loop) inside the ASP code, as to change the title of my buttons with the corresponding value

<% for (int i =1; i<11; i++){ %>
<asp:ButtonID="Button1"runat="server"Text="x"Width="41px"/>

<%;} %>

I tried using <%i%> because the suggestions online keep saying to do that, but all that does it output the literal signs, not the variable content, and I cannot leave the "" out either, because I am not allowed to use the <%%>
inside that part of the code.


I would also like to change the position somehow, as to make , for instance 10 X 10 buttons.
For some reason I cant figure out how to take my C# /java skills on this into ASP
 
W

wwjd_kilden

Guest
*BUMP*

So I wont have to make a new thread :D

--------
I could use some bright mySQl heads. My brain doesn't like being logical :D

I am making a program vaguely similar to one at work, where we can view info on: Contracts, Machines , Contacts

There can be several contacts for each machine, as we list whoever makes the call. How do I do this in my database?

For now I have tables: Machine (Serial, type, name), Contact (id ++) , Shipto_party (id + company info) , and ownership (mc serial, company id, contract).

where do I place my foreign key to keep track of my contacts?