java swing undecorated moveable jframe form
Ever since i have seen a key-gen , i was curious about how to make one in java.this is some of the progress along the way, the moveable yet no window controllers and play pause chip-tune music with transparent background.so far i have accomplished my task.
AWTUtilities.setWindowOpacity(this, 0.8f); <- this is line responsible for windows transparency level.
AWTUtilities.setWindowOpaque(this, false); <- this line is for controlling frames backgroung opaqe
moving the undecorated frame
private void CaptureMove() {
this.addMouseMotionListener(new MouseMotionAdapter() {
@Override
public void mouseDragged(MouseEvent event) {
try {
Point point_location = event.getPoint();
if (DRAG_START == null) {
DRAG_START = point_location;
}
CURRUNT_LOCATION = point_location;
Point location = getLocation();
setLocation(location.x + (CURRUNT_LOCATION.x - DRAG_START.x),
location.y + (CURRUNT_LOCATION.y - DRAG_START.y));
} catch (Exception e) {
}
}
});
this.addMouseListener(new MouseAdapter() {
@Override
public void mouseReleased(MouseEvent event) {
try {
Point point_location = getLocation();
setLocation(point_location.x + (CURRUNT_LOCATION.x - DRAG_START.x),
point_location.y + (CURRUNT_LOCATION.y - DRAG_START.y));
DRAG_START = null;
} catch (Exception e) {
}
}
});
}
playing the chip-tune
private synchronized void play() {
if (ibxm != null) {
playing = true;
playThread = new Thread(new Runnable() {
@Override
public void run() {
int[] mixBuf = new int[ibxm.getMixBufferLength()];
byte[] outBuf = new byte[mixBuf.length * 4];
AudioFormat audioFormat = null;
SourceDataLine audioLine = null;
try {
audioFormat = new AudioFormat(SAMPLE_RATE, 16, 2, true, true);
audioLine = AudioSystem.getSourceDataLine(audioFormat);
audioLine.open();
audioLine.start();
while (playing) {
int count = getAudio(mixBuf);
int outIdx = 0;
for (int mixIdx = 0, mixEnd = count * 2; mixIdx < mixEnd; mixIdx++) {
int ampl = mixBuf[mixIdx];
if (ampl > 32767) {
ampl = 32767;
}
if (ampl < -32768) {
ampl = -32768;
}
outBuf[outIdx++] = (byte) (ampl >> 8);
outBuf[outIdx++] = (byte) ampl;
}
audioLine.write(outBuf, 0, outIdx);
}
audioLine.drain();
} catch (Exception e) {
} finally {
if (audioLine != null && audioLine.isOpen()) {
audioLine.close();
}
}
}
});
playThread.start();
Play.setText("||");
}
}
public void LoadMoDFile() {
String path = System.getProperty("user.dir") + System.getProperty("file.separator") + "cptun.xmfile";
File ff = new File(path);
try {
loadModule(ff);
} catch (IOException ex) {
System.out.println("" + ex);
}
}
private synchronized void loadModule(File modFile) throws IOException {
byte[] moduleData = new byte[(int) modFile.length()];
FileInputStream inputStream = new FileInputStream(modFile);
int offset = 0;
while (offset < moduleData.length) {
int len = inputStream.read(moduleData, offset, moduleData.length - offset);
if (len < 0) {
throw new IOException("Unexpected end of file.");
}
offset += len;
}
inputStream.close();
module = new Module(moduleData);
ibxm = new IBXM(module, SAMPLE_RATE);
}