Posts

Showing posts from 2010

How to display a control in JPanel during runtime

I had a problem in a Java project about not able to display a JTree into a JPanel. The JPanel is created during design time. The problem is JTree is created during runtime and adding the JTree into the JPanel will not display the control when executing the application. The code below won't work: JTree treeObject = new JTree(); panelObject.add(treeObject); There is one more thing to do to make it work by adding a group layout. //---------- START JTree treeObject = new JTree(); panelObject.add(treeObject); javax.swing.GroupLayout myLayout = new javax.swing.GroupLayout(panelObject); panelObject.setLayout(myLayout); myLayout.setHorizontalLayout(       myLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)      .addComponent(treeObject, panelObject.getWidth(), panelObject.getWidth(), panelObject.getWidth()) ); myLayout.setVerticalGroup(       myLayout.createParallelGroup(javax....

How to add and delete contents in menu.lst in Linux

I was creating a RPM for Linux in one of my projects. I needed to add contents to the menu.lst which is found in /boot/grub/. The operating system that I'm using is Suse. There are two problems that needs to be done. 1. Need to add content to the file 2. Remove the content from the file. I use the bash script to do both. To add content to the file:  cat /boot/grub/menu.tmp >> /boot/grub/menu.lst  wc -l /boot/grub/menu.lst > /boot/grub/menu.lstcount The first line is to append the content in menu.tmp to  menu.lst. The second is count the number of lines in the menu.lst and save the result to menu.lstcount. To delete the content of the file: num=`grep -o ".*[0-9]" /boot/grub/menu.lstcount` let begin=$num-3 mv /boot/grub/menu.lst /boot/grub/menu.orig sed "$begin,$num"d /boot/grub/menu.orig > /boot/grub/menu.lst The first line is retrieve the line number stored in menu.lstcount Second line is to assign the difference of the line numb...

Initialing a boolean variable thru comparison operator

There are time when we try to compare and the point is only to initialize a boolean variable. Sample, if(var1 == var2) {   bVar = true; } else {   bVal = false; } So, instead of the long code above you can shorten it to: bVar = (var1 == var2); That's it!

Calling unmanaged DLL in C#.NET

I have a project that created a DLL but somehow I wanted to know if the current DLL I have is the same with the project. So, I created a form project in C# and calling the function. Sample below: using System.Windows.Forms; using System.Runtime.InteropServices; // DllImport namespace DLLTester {   public partial class Form1 : Form {  public Form1( ) {    InitializeComponent(); }   private void button1_Click( object sender, EventArgs e )  {      MessageBox.Show(WrapperClassOfDLL .EnableDevice().ToString());  } } public class WrapperClassOfDLL { [DllImport("MyUnmanagedDLL.dll")] public static extern UInt32 GetVersion( ); } } Put the DLL in the project directory and make sure the function signature is the same in the DLL. That's it!

Digital Logic

I created a project named Digital Logic. Digital Logic can create any logic gates you want. You can use the Base namespace to create your own customized gates or inherit the ones I already implemented in Base.Gates namespace. For now, only a few gates were implemented but I will add more in the coming days. First, you'll need to have the DigitalLogic.cab. Extract the DLLs and save it in your working folder. Add the DLLs into your project references. Sample code: int main() {    AND andGate = new AND();   andGate.Input(1, true);   andGate.Input(2, false);   if(andGate.Output == false) MessageBox("Correct");   else MessageBox("Wrong");   return ; } You can download the files here Digital Logic Enjoy!