[SOLVED] Help with a simple script
Hi guys! A problem is connected with switching cpu governors. Usually I set it by commands and made alias in .bashrc:
sudo cpufreq-set -c 0 -g performance && sudo cpufreq-set -c 1 -g performance
sudo cpufreq-set -c 0 -g ondemand && sudo cpufreq-set -c 1 -g ondemand
sudo cpufreq-set -c 0 -g powersave && sudo cpufreq-set -c 1 -g powersave
Could you help me with script which can read system information about current cpu governor and switches the next governor
Last edited by noMaster (2012-01-27 06:36:55)
noMaster wrote:
JuseBox wrote:Can you please be more specific with what you are trying to accomplish?
I need that script for set it on hotkey and change cpu states. Unfortunately I havent scripting experience
I make one thing but it doesnt work for me
### Toggle Super Hybrid Engine ##################################
she_names=("performance" "ondemand" "powersave")
she_value_performance=( "0" "performance")
she_value_ondemand=( "1" "ondemand")
she_value_powersave=( "2" "powersave")
# Find current
she_current=`cat /sys/devices/system/cpu/cpu0/cpufreq/scaling_governor`
if [[ "${she_current}" == "${she_value_performance[0]}" ]]; then
she_next=${she_value_ondemand[0]}
elif [[ "${she_current}" == "${she_value_ondeman[1]}" ]]; then
she_next=${she_value_powersave[0]}
elif [[ "${she_current}" == "${she_value_powersave[1]}" ]]; then
she_next=${she_value_performance[0]}
fi
function she_toggle() {
if [[ "${she_names[${she_current}]}" != "${she_names[${she_next}]}" ]]; then
cmd="/usr/bin/notify-send -t 5000 SHE changed"
echo ${she_next} > ${she_current}
else
cmd="/usr/bin/notify-send -t 5000 SHE original"
fi
case $1 in
# "debug")
# print_debug
"powersave")
she_next=2
she_toggle
"normal")
she_next=1
she_toggle
"performance")
she_next=0
she_toggle
she_toggle
esac
### End of file #################################################
I am looking over the script. Without it, do you think you could explain what your trying to accomplish? What states and when should they toggle? Something rough to get an idea? I think if I am thinking correctly this could be easier then it seems. I will help ya.
Similar Messages
-
[SOLVED] Help with systemd .service script
Hello,
I have been using ArchLinux (ARM version) on some “plug computers” for over a year and love it. Recently I forced myself to move to systemd by upgrading all my computers from scratch. I migrated all my applications and learned new ways of doing things but am having trouble with one last migration. I run a c++ communication program that monitors a TCP port for traffic. In the past I started this program (daemon) from an entry in rc.conf. I have read all I can about systemd’s new approach to starting daemons (https://wiki.archlinux.org/index.php/Systemd and https://wiki.archlinux.org/index.php/Systemd/Services)
So far I created what I thought is the correct systemd .service file listed below.
[Unit]
Description=EQBCS
After=network.target
[Service]
Type=simple
ExecStart=/home/public/EQBCS/eqbcs -p 12947 -d &> /dev/null
[Install]
WantedBy=multi-user.target
I put this file in /usr/lib/systemd/system/eqbcs.service. I then ran the following commands in the following order:
systemctl daemon-reload
systemctl enable eqbcs.service (created a link in /etc/systemd/system/multi-user.target.wants)
systemctl start eqbcs.service
Here is output from systemctl (status)
eqbcs.service loaded failed failed EQBCS
I thought this would start the service but no luck. I also thought maybe a reboot would work but no luck. I verified I can start the daemon manually if I run /home/public/EQBCS/eqbcs -p 12947 -d &> /dev/null from the command line.
I think I am close, but after several hours of looking at examples of .service files and other posts, I am at a loss. I am not one of those types who posts a question without taking the time to read the wealth of information on these boards, but I am truly out of ideas and can’t figure out what to do next. I sincerely could use some help/advice.
Last edited by calzon65 (2013-06-01 21:18:20)Thank you for the suggestions, I believe I am getting closer to success. When I run systemctl start eqbcs.servcie it starts the service but the only way I can get out of systemctl is to ^c out.
Here is my current .service file:
[Unit]
Description=EQBCS
After=network.target
[Service]
ExecStart=/home/public/EQBCS/eqbcs -p 12947
Type=forking
[Install]
WantedBy=multi-user.target
Output from systemctl status eqbcs:
eqbcs.service - EQBCS
Loaded: loaded (/etc/systemd/system/eqbcs.service; enabled)
Active: failed (Result: timeout) since Sat 2013-06-01 12:48:43 PDT; 2min 11s ago
Process: 427 ExecStart=/home/public/EQBCS/eqbcs -p 12947 (code=killed, signal=TERM)
Main PID: 396 (code=killed, signal=KILL)
CGroup: name=systemd:/system/eqbcs.service
Jun 01 12:47:13 alarm systemd[1]: Starting EQBCS...
Jun 01 12:47:13 alarm eqbcs[427]: WARNING: Running as root NOT recommended.
Jun 01 12:47:13 alarm eqbcs[427]: EQ Box Chat Server 10.12.18
Jun 01 12:47:13 alarm eqbcs[427]: Waiting for connections on port: 12947...
Jun 01 12:48:43 alarm systemd[1]: eqbcs.service operation timed out. Terminating.
Jun 01 12:48:43 alarm systemd[1]: Failed to start EQBCS.
Jun 01 12:48:43 alarm systemd[1]: Unit eqbcs.service entered failed state.
Are there any other suggestions for settings in my .service file? -
Hello,
I am trying to search through a large group of files for a list of strings. I have my my list called list.txt which is just a carriage return separated list of 800 strings. I want to search a group of files for the string, and if it finds it, output the line to a file. What it is doing is creating the logfile even if it doesn't find the string. Since my list is 800 items and it's searching thousands of files I don't want all the logfiles generated if it's not finding the match. Here is what I have and it is working.
#!/bin/sh
for list in `cat list.txt`
do
grep $list /u01/h/nomadd/archive/xml_archive/P3I_214A_20130522* > /u04/temp/xml/${list}_findings3.log 2>&1
find /u04/temp/xml/ -name '*.log' -size 0 -print0 | xargs -0 rm
doneWhat I would like to do is get rid of the find and remove and not generate the log file if there is nothing in it. The find is really slowing down the processing.
ThanksHow about the following example. You can easily customize it to your needs.
1. Create some sample files:
$ mkdir sample1
$ cd sample1
$ for (( i=1; i<=10; i++ )); do echo -e "${i}1\n${i}2" > file$i.txt; done
$ echo -e "11\n32\n51\n72\n91" > search.inf
$ ls
file10.txt file2.txt file4.txt file6.txt file8.txt search.inf
file1.txt file3.txt file5.txt file7.txt file9.txt 2. Create a script, e.g. "search" with following content:
#!/bin/bash
# Filename: search
# Author: Dude
# Purpose: Search file content demo
logfile=logfile.lst
for file in *.txt; do
lnr=0
while read line; do
(( lnr++ ))
for item in $(cat search.inf); do
[ $(echo $line | grep "$item") ] && \
echo "Found $item in $file, line $lnr." >> $logfile
done
done < $file
done
#eof3. Save the file and set execute privileges
chmod u+x search4. Test the result:
./search
cat logfile.lst
Found 11 in file1.txt, line 1.
Found 32 in file3.txt, line 2.
Found 51 in file5.txt, line 1.
Found 72 in file7.txt, line 2.
Found 91 in file9.txt, line 1. -
[solved]Need help with a bash script for MOC conky artwork.
I need some help with a bash script for displaying artwork from MOC.
Music folders have a file called 'front.jpg' in them, so I need to pull the current directory from MOCP and then display the 'front.jpg' file in conky.
mocp -Q %file
gives me the current file playing, but I need the directory (perhaps some way to use only everything after the last '/'?)
A point in the right direction would be appreciated.
thanks, d
Last edited by dgz (2013-08-29 21:24:28)Xyne wrote:
You should also quote the variables and output in double quotes to make the code robust, e.g.
filename="$(mocp -Q %file)"
dirname="${filename%/*}"
cp "$dirname"/front.jpg ~/backup/art.jpg
Without the quotes, whitespace will break the code. Even if you don't expect whitespace in any of the paths, it's still good coding practice to include the quotes imo.
thanks for the tip.
here it is, anyhow:
#!/bin/bash
filename=$(mocp -Q %file)
dirname=${filename%/*}
cp ${dirname}/front.jpg ~/backup/art.jpg
then in conky:
$alignr${execi 30 ~/bin/artc}${image ~/backup/art.jpg -s 100x100 -p -3,60}
thanks for the help.
Last edited by dgz (2013-08-29 21:26:32) -
Need help making a simple script for my webcam
Hey everyone, fairly new to applescript programming. I just bought a usb camera for my macbook because I use it for video conferencing/playing around, and it is better quality than the built in isight. However, in order to use this camera I need to use drivers from a program called camTwist. This being said camTwist needs to be opened first and the usb camera must be selected from camTwist Step 1 list in order for any other application to use the camera. I just want to make a simple program that would open camTwist first, then select "webcam" from the list (double click it like I always have to in order to select it) in order to activate the driver, and then open photo booth which would then be using the camTwist driver in order to take pictures.
I made a crude program but it does not automatically select "webcam" from the Step 1 list in camTwist:
tell application "CamTwist" to activate
delay 10
tell application "Photo Booth" to activate
that’s basically it. I set the delay to 10 seconds so that when camTwists boots up first I can manually select my webcam. HOWEVER, I would like to make a script that would boot up CamTwist first, select my webcam from the list automatically, and then open Photo Booth with the CamTwist webcam driver already selected.
Don't know much about applescript so any help to make a working script to solve my problem would be greatly appreciated! Thanks!Solved my problem but now I need help with something else! First I used CamTwist user options to create user defined hot keys with the specific purpose to load the webcam. I chose Command+B. I tested it out in CamTwist and it worked. The program follows a logical order from there. First it loads CamTwist, then after a short delay it presses the hot keys in order to load the webcam from the video source list, then another short delay and Photo Booth is opened with the driver loaded from camTwist. Everything works Perfect! Here's the code:
tell application "System Events"
tell application "CamTwist" to activate
delay 0.5
--Press command+b which is a user defined hot key to load webcam
key code 11 using command down
end tell
delay 0.5
tell application "Photo Booth" to activate
My Next question is, would it be possible with this same script to have both applications quit together. For example I always quit Photo Booth first, so when I quit photo booth is there a way to make CamTwist also quit and keep everything within the same script? Please let me know. This forum has been very helpful and lead me to a solution to my problem! Hoping I can solve this next problem as well! Thanks everyone. -
Help with first Adobe Script for AE?
Hey,
I'm trying to create a script that will allow me to set a certain number of layer markers at an even interval to mark out a song. Could someone help me troubleshoot this script? I've been working on it for ages now, and I'm about to snap. I've basically gone from HTML and CSS, to javascript and Adobe scripting in the past few hours, and I cannot figure this out for the life of me.
I want to create a dialog with two fields, the number of markers to place, and the tempo of the song. Tempo is pretty simple, its just the number of beats per minute. The script is meant to start at a marker that I have already placed, and set a new marker at incrementing times. Its mainly to help me see what I'm trying to animate too, even if the beat is a little hard to pick up every once in a while.
Also, is there a better way to do this? This script will help me in the long run because I will need to do this pretty often, but I'm wondering if there was something that I could not find online that would have saved me these hours of brain-jumbling?
Thank you very much for any help you can offer.
// Neo_Add_MultiMarkers.jsx
//jasondrey13
//2009-10-26
//Adds multiple markers to the selected layer.
// This script prompts for a certain number of layer markers to add to the selected audio layer,
//and an optional "frames between" to set the number of frames that should be skipped before placing the next marker
// It presents a UI with two text entry areas: a Markers box for the
// number of markers to add and a Frames Between box for the number of frames to space between added markers.
// When the user clicks the Add Markers button,
// A button labeled "?" provides a brief explanation.
function Neo_Add_MultiMarkers(thisObj)
// set vars
var scriptName = "Neoarx: Add Multiple Markers";
var numberOfMarkers = "0";
var tempo = "0";
// This function is called when the Find All button is clicked.
// It changes which layers are selected by deselecting layers that are not text layers
// or do not contain the Find Text string. Only text layers containing the Find Text string
// will remain selected.
function onAddMarkers()
// Start an undo group. By using this with an endUndoGroup(), you
// allow users to undo the whole script with one undo operation.
app.beginUndoGroup("Add Multiple Markers");
// Get the active composition.
var activeItem = app.project.activeItem;
if (activeItem != null && (activeItem instanceof CompItem)){
// Check each selected layer in the active composition.
var activeComp = activeItem;
var layers = activeComp.selectedLayers;
var markers = layers.property("marker");
//parse ints
numberOfMarkers = parseInt (numberOfMarkers);
tempo = parseInt (tempo);
// Show a message and return if there is no value specified in the Markers box.
if (numberOfMarkers < 1 || tempo < 1) {
alert("Each box can take only positive values over 1. The selection was not changed.", scriptName);
return;
if (markers.numKeys < 1)
alert('Please set a marker where you would like me to begin.');
return;
var beginTime = markers.keyTime( 1 );
var count = 1;
var currentTime = beginTime;
var addPer = tempo/60;
while(numberOfMarkers < count)
markers.setValueAtTime(currentTime, MarkerValue(count));
currentTime = currentTime + addPer;
if (count==numberOfMarkers) {
alert('finished!');
return;
else{
count++;
app.endUndoGroup();
// Called when the Markers Text string is edited
function onMarkersStringChanged()
numberOfMarkers = this.text;
// Called when the Frames Text string is edited
function onFramesStringChanged()
tempo = this.text;
// Called when the "?" button is clicked
function onShowHelp()
alert(scriptName + ":\n" +
"This script displays a palette with controls for adding a given number of markers starting at a pre-placed marker, each separated by an amount of time determined from the inputted Beats Per Minute (Tempo).\n" +
"It is designed to mark out the even beat of a song for easier editing.\n" +
"\n" +
"Type the number of Markers you would like to add to the currently selected layer. Type the tempo of your song (beats per minute).\n" +
"\n" +
"Note: This version of the script requires After Effects CS3 or later. It can be used as a dockable panel by placing the script in a ScriptUI Panels subfolder of the Scripts folder, and then choosing this script from the Window menu.\n", scriptName);
// main:
if (parseFloat(app.version) < 8)
alert("This script requires After Effects CS3 or later.", scriptName);
return;
else
// Create and show a floating palette
var my_palette = (thisObj instanceof Panel) ? thisObj : new Window("palette", scriptName, undefined, {resizeable:true});
if (my_palette != null)
var res =
"group { \
orientation:'column', alignment:['fill','fill'], alignChildren:['left','top'], spacing:5, margins:[0,0,0,0], \
markersRow: Group { \
alignment:['fill','top'], \
markersStr: StaticText { text:'Markers:', alignment:['left','center'] }, \
markersEditText: EditText { text:'0', characters:10, alignment:['fill','center'] }, \
FramesRow: Group { \
alignment:['fill','top'], \
FramesStr: StaticText { text:'Tempo:', alignment:['left','center'] }, \
FramesEditText: EditText { text:'140', characters:10, alignment:['fill','center'] }, \
cmds: Group { \
alignment:['fill','top'], \
addMarkersButton: Button { text:'Add Markers', alignment:['fill','center'] }, \
helpButton: Button { text:'?', alignment:['right','center'], preferredSize:[25,20] }, \
my_palette.margins = [10,10,10,10];
my_palette.grp = my_palette.add(res);
// Workaround to ensure the editext text color is black, even at darker UI brightness levels
var winGfx = my_palette.graphics;
var darkColorBrush = winGfx.newPen(winGfx.BrushType.SOLID_COLOR, [0,0,0], 1);
my_palette.grp.markersRow.markersEditText.graphics.foregroundColor = darkColorBrush;
my_palette.grp.FramesRow.FramesEditText.graphics.foregroundColor = darkColorBrush;
my_palette.grp.markersRow.markersStr.preferredSize.width = my_palette.grp.FramesRow.FramesStr.preferredSize.width;
my_palette.grp.markersRow.markersEditText.onChange = my_palette.grp.markersRow.markersEditText.onChanging = onMarkersStringChanged;
my_palette.grp.FramesRow.FramesEditText.onChange = my_palette.grp.FramesRow.FramesEditText.onChanging = onFramesStringChanged;
my_palette.grp.cmds.addMarkersButton.onClick = onAddMarkers;
my_palette.grp.cmds.helpButton.onClick = onShowHelp;
my_palette.layout.layout(true);
my_palette.layout.resize();
my_palette.onResizing = my_palette.onResize = function () {this.layout.resize();}
if (my_palette instanceof Window) {
my_palette.center();
my_palette.show();
} else {
my_palette.layout.layout(true);
else {
alert("Could not open the user interface.", scriptName);
Neo_Add_MultiMarkers(this);You should ask such questions over at AEnhancers. I had a quick look at your code but could not find anything obvious, so it may relate to where and when you execute certain functions and how they are nested, I just don't have the time to do a deeper study.
Mylenium -
Help with web form script. PHP, CGI, Perl???
anyone willing to help with a web form script? I have a form built, but cant seem to figure out the scripting! Should I be using Perl, CGI, PHP... What do I need to enable? I am a complete novice when it comes to scripts. Looking for a little friendly help.
Here is a simple bit of PHP to stick in the page your form posts to. You would need to edit the first three variables to your liking, and add the html you want to serve afterwards:
<pre>
<?php
$emailFrom = '[email protected]';
$emailTo = '[email protected]';
$emailSubject = 'Subject';
$date = date('l, \t\h\e dS \o\f F, Y \a\t g:i A');
$browser = $HTTPSERVER_VARS['HTTP_USERAGENT'];
$hostname = $HTTPSERVER_VARS['REMOTEADDR'];
$message = "$date\n\nAddress: $hostname\nBrowser: $browser\n\n";
foreach ($_POST as $key => $value) {
$message .= $key . ": " . $value . "\n";
$mailResult = mail($emailTo,$emailSubject,$message,"From: $emailFrom");
?>
</pre>
This script will grab the server's date and the submitter's address and browser type. It will then list the name and value of each form field you have put on your form.
Also, this script expects your form method="post".
Lastly, you can offer alternate text later on in your html page based on the success of the above script with a snippet like this:
<pre><?php
if ($mailResult) {
echo "Your comments have been received thank you.";
} else {
echo "There was an error. Please try again or contact us using an alternate method.";
?></pre> -
Help with Custom calculation script in Acrobat 8
Hi all, I am using acrobat 8 on OS 10.5
I am trying to add certain fields (numbers) and then subtract another field value to give an end result.
I don't know anything about Javascript, would anyone be able to help with any info on how I achieve this result? I can only see Add, x and average etc... nothing there for subtraction
Thanks for any help in advance
SwenThis should get you started:
>if (event) {
// get values from two text fields
var a = Number(this.getField('Text1').value);
var b = Number(this.getField('Text2').value);
// subtract the values and show it
this.event.target.value = a - b;
Place this in a 3d text field, as a Custom Calculation Script. -
Help with a simple applescript for combining Artist text with Track name
Hi all,
I'd like to put together a simple script that takes the artist names from a list of tracks in iTunes and copies the text to the start of the Title name, followed by " - ".
This is because, e.g. on a classical album, I want the artist names to all be "Classic Collection Gold" but I'd like to keep the artist name contained with the track name. This means when I browse by artist I don't get millions of artists...
I found this script, which does something kinda similar, but I'm new to script writing so not sure how to do it?
So I'd like to change:
Name
Planets: Mars
Artist
Gustav Holst
Ambum:
Simply Classical Gold (Disc 2)
To be:
Gustav Holst - Planets: Mars
Artist
Gustav Holst - Planets: Mars OR BETTER Simply Classical Gold (Disc 2)
Album
Simply Classical Gold (Disc 2)
This script has some ideas in, but I'm not sure how to tweak it....
"Artist - Name Corrector" for iTunes
written by Doug Adams
[email protected]
v1.6 May 17, 2004
-- removed ref to selection
v1.5 April 11 2004
checks if separator string is in name
v1.0 April 2 2004
Get more free AppleScripts and info on writing your own
at Doug's AppleScripts for iTunes
http://www.malcolmadams.com/itunes/
property separator : " - "
tell application "iTunes"
if selection is not {} then
set sel to selection
repeat with aTrack in sel
tell aTrack
if (get name) contains separator then
set {artist, name} to my texttolist(get name, separator)
end if
end tell
end repeat
end if
end tell
-- == == == == == == == == == == == == == == == ==
on texttolist(txt, delim)
set saveD to AppleScript's text item delimiters
try
set AppleScript's text item delimiters to {delim}
set theList to every text item of txt
on error errStr number errNum
set AppleScript's text item delimiters to saveD
error errStr number errNum
end try
set AppleScript's text item delimiters to saveD
return (theList)
end texttolist
Message was edited by: ChipstixI'm not sure what that script thinks it's doing, but it's essentially doing nothing, so scrub that and start afresh.
The first thing you need is a way to identify the tracks to change - you don't want to do all tracks in the library (they might have already been munged). A good option is to work on the selected tracks:
tell application "iTunes"
if selection is not {} then
set sel to selection
You then need to iterate through those items, changing them one-by-one:
repeat with aTrack in sel
Now comes the easy part - build a list of the elements you want (in this case you want the name, artist, and album of each track:
set trackName to name of aTrack
set trackArtist to artist of aTrack
set trackAlbum to album of aTrack
Now you have the information you need, so reset the fields as appropriate:
set name of aTrack to trackArtist & " - " & trackName
set artist of aTrack to trackAlbum -- or to trackArtist & " - " & trackName, depending on your choice
Now clean up by closing off the repeat and tell blocks:
end repeat
end tell
Putting it all together you get:
tell application "iTunes"
if selection is not {} then
set sel to selection
repeat with aTrack in sel
set trackName to name of aTrack
set trackArtist to artist of aTrack
set trackAlbum to album of aTrack
set name of aTrack to trackArtist & " - " & trackName
set artist of aTrack to trackAlbum -- or to trackArtist & " - " & trackName, depending on your choice
end repeat
end tell -
Need help with a simple process with FTP Adapter and File Adapter
I am trying out a simple BPEL process that gets a file in opaque mode from a FTP server using a FTP adapter and writes it to the local file system using a File Adapter. However, the file written is always empty (zero bytes). I then tried out the FTPDebatching sample using the same FTP server JNDI name and this work fine surprisingly. I also verified by looking at the FTP server logs that my process actually does hit the FTP server and seems to list the files based on the filtering condition - but it does not issue any GET or RETR commands to actually get the files. I am suspecting that the problem could be in the Receive, Assign or Invoke activities, but I am not able identify what it is.
I can provide additional info such as the contents of my bpel and wsdl files if needed.
Would appreciate if someone can help me with this at the earliest.
Thanks
Jaypersiandude wrote:
Topic: Need help with if, else, and which statements and loops.
How would I display 60 < temp. <= 85 in java
System.out.println("60 < temp. <= 85 in java");
another question is how do I ask a question like want to try again (y/n) after a output and asking that everytime I type in yes after a output and terminate when saying No.Sun's [basic Java tutorial|http://java.sun.com/docs/books/tutorial/]
Sun's [New To Java Center|http://java.sun.com/learning/new2java/index.html].Includes an overview of what Java is, instructions for setting up Java, an intro to programming (that includes links to the above tutorial or to parts of it), quizzes, a list of resources, and info on certification and courses.
[http://javaalmanac.com|http://javaalmanac.com]. A couple dozen code examples that supplement [The Java Developers Almanac|http://www.amazon.com/exec/obidos/tg/detail/-/0201752808?v=glance].
jGuru. A general Java resource site. Includes FAQs, forums, courses, more.
JavaRanch. To quote the tagline on their homepage: "a friendly place for Java greenhorns." FAQs, forums (moderated, I believe), sample code, all kinds of goodies for newbies. From what I've heard, they live up to the "friendly" claim.
Bruce Eckel's [Thinking in Java|http://mindview.net/Books/DownloadSites] (Available online.)
Joshua Bloch's [Effective Java|http://www.amazon.com/Effective-Java-2nd-Joshua-Bloch/dp/0321356683/ref=pd_bbs_1?ie=UTF8&s=books&qid=1214349768&sr=8-1]
Bert Bates and Kathy Sierra's [Head First Java|http://www.amazon.com/exec/obidos/tg/detail/-/0596004656?v=glance].
James Gosling's [The Java Programming Language|http://www.bookpool.com/sm/0321349806]. -
Need help with a simple basketball game.
Hi im new here and I need help with making this simple basketball game.
Im trying to recreate this game from this video. Im not sure if he is using as2 or as3
Or if anyone could help me make a game like this or direct me to a link on how to do it It would be greatly appreciated.If you couldn't tell whether it is AS2 or AS3, it is doubtful you can turn it from AS2 into AS3, at least not until you learn both languages. There is no tool made that does it for you.
-
Need help with a simple program (should be simple anyway)
I'm (starting to begin) writing a nice simple program that should be easy however I'm stuck on how to make the "New" button in the file menu clear all the fields. Any help? I'll attach the code below.
====================================================
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
public class Message extends JFrame implements ActionListener {
public void actionPerformed(ActionEvent evt) {
text1.setText(" ");
text2.setText("RE: ");
text3.setText(" ");
public Message() {
super("Write a Message - by Kieran Hannigan");
setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
setSize(370,270);
FlowLayout flo = new FlowLayout(FlowLayout.RIGHT);
setLayout(flo);
//Make the bar
JMenuBar bar = new JMenuBar();
//Make "File" on Menu
JMenu File = new JMenu("File");
JMenuItem f1 = new JMenuItem("New");f1.addActionListener(this);
JMenuItem f2 = new JMenuItem("Open");
JMenuItem f3 = new JMenuItem("Save");
JMenuItem f4 = new JMenuItem("Save As");
JMenuItem f5 = new JMenuItem("Exit");
File.add(f1);
File.add(f2);
File.add(f3);
File.add(f4);
File.add(f5);
bar.add(File);
//Make "Edit" on menu
JMenu Edit = new JMenu("Edit");
JMenuItem e1 = new JMenuItem("Cut");
JMenuItem e2 = new JMenuItem("Paste");
JMenuItem e3 = new JMenuItem("Copy");
JMenuItem e4 = new JMenuItem("Repeat");
JMenuItem e5 = new JMenuItem("Undo");
Edit.add(e5);
Edit.add(e4);
Edit.add(e1);
Edit.add(e3);
Edit.add(e2);
bar.add(Edit);
//Make "View" on menu
JMenu View = new JMenu("View");
JMenuItem v1 = new JMenuItem("Bold");
JMenuItem v2 = new JMenuItem("Italic");
JMenuItem v3 = new JMenuItem("Normal");
JMenuItem v4 = new JMenuItem("Bold-Italic");
View.add(v1);
View.add(v2);
View.add(v3);
View.addSeparator();
View.add(v4);
bar.add(View);
//Make "Help" on menu
JMenu Help = new JMenu("Help");
JMenuItem h1 = new JMenuItem("Help Online");
JMenuItem h2 = new JMenuItem("E-mail Programmer");
Help.add(h1);
Help.add(h2);
bar.add(Help);
setJMenuBar(bar);
//Make Contents of window.
//Make "Subject" text field
JPanel row2 = new JPanel();
JLabel sublabel = new JLabel("Subject:");
row2.add(sublabel);
JTextField text2 = new JTextField("RE:",24);
row2.add(text2);
//Make "To" text field
JPanel row1 = new JPanel();
JLabel tolabel = new JLabel("To:");
row1.add(tolabel);
JTextField text1 = new JTextField(24);
row1.add(text1);
//Make "Message" text area
JPanel row3 = new JPanel();
JLabel Meslabel = new JLabel("Message:");
row3.add(Meslabel);
JTextArea text3 = new JTextArea(6,22);
messagearea.setLineWrap(true);
messagearea.setWrapStyleWord(true);
JScrollPane scroll = new JScrollPane(text3,
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
//SpaceLine
JPanel spaceline = new JPanel();
JLabel spacer = new JLabel(" ");
spaceline.add(spacer);
row3.add(scroll);
add(row1);
add(row2);
add(spaceline);
add(spaceline);
add(row3);
setVisible(true);
public static void main(String[] arguments) {
Message Message = new Message();
}persiandude wrote:
Topic: Need help with if, else, and which statements and loops.
How would I display 60 < temp. <= 85 in java
System.out.println("60 < temp. <= 85 in java");
another question is how do I ask a question like want to try again (y/n) after a output and asking that everytime I type in yes after a output and terminate when saying No.Sun's [basic Java tutorial|http://java.sun.com/docs/books/tutorial/]
Sun's [New To Java Center|http://java.sun.com/learning/new2java/index.html].Includes an overview of what Java is, instructions for setting up Java, an intro to programming (that includes links to the above tutorial or to parts of it), quizzes, a list of resources, and info on certification and courses.
[http://javaalmanac.com|http://javaalmanac.com]. A couple dozen code examples that supplement [The Java Developers Almanac|http://www.amazon.com/exec/obidos/tg/detail/-/0201752808?v=glance].
jGuru. A general Java resource site. Includes FAQs, forums, courses, more.
JavaRanch. To quote the tagline on their homepage: "a friendly place for Java greenhorns." FAQs, forums (moderated, I believe), sample code, all kinds of goodies for newbies. From what I've heard, they live up to the "friendly" claim.
Bruce Eckel's [Thinking in Java|http://mindview.net/Books/DownloadSites] (Available online.)
Joshua Bloch's [Effective Java|http://www.amazon.com/Effective-Java-2nd-Joshua-Bloch/dp/0321356683/ref=pd_bbs_1?ie=UTF8&s=books&qid=1214349768&sr=8-1]
Bert Bates and Kathy Sierra's [Head First Java|http://www.amazon.com/exec/obidos/tg/detail/-/0596004656?v=glance].
James Gosling's [The Java Programming Language|http://www.bookpool.com/sm/0321349806]. -
Help with a simple program.
I need some help writing a simple program. Can anybody help??
thanks to all.
2. HTML Java Source Code Reserved Word Highlighter
Write a program that inputs a Java source code file and outputs a copy of that file with Java keywords surrounded with HTML tags for bold type. For example this input:
public class JavaSource
public static void main ( String[] args )
if ( args.length == 3 )
new BigObject();
else
System.out.println("Too few arguments.");
will be transformed into:
<B>public</B> <B>class</B> JavaSource
<B>public</B> <B>static</B> <B>void</B> main ( String[] args )
<B>if</B> ( args.length == 3 )
<B>new</B> BigObject();
<B>else</B>
System.out.println("Too few arguments.");
In a browser the code will look like this:
public class JavaSource
public static void main ( String[] args )
if ( args.length == 3 )
new BigObject();
else
System.out.println("Too few arguments.");Here is something that may get you started...
import java.io.*;
import java.util.*;
public class HtmlJava{
public static void main(String arg[]){
if(arg.length!=1){
System.out.println("Usage java HtmlJava sourceFile");
else
new HtmlJava(arg[0]);
HtmlJava(String source){
try{
BufferedReader sourceReader=new BufferedReader(new InputStreamReader(new FileInputStream(source)));
BufferedWriter writer=new BufferedWriter(new OutputStreamWriter(new FileOutputStream(source+"Html.txt")));
Vector keywords=new Vector();
addKeywords(keywords);
String line;
StringTokenizer tokenizer=null;
String word;
while((line=sourceReader.readLine () )!=null){
tokenizer=new StringTokenizer(line);
while(tokenizer.hasMoreTokens()){
word=tokenizer.nextToken();
if(keywords.contains(word)){
writer.write(""+word+" ");
else{
writer.write(word+" ");
writer.write("\r\n");
writer.close();
sourceReader.close();
System.out.println("Output File written to "+source+"Html.txt");
catch(Exception ex){
ex.printStackTrace();
private void addKeywords(Vector keywords){
keywords.addElement ( "abstract");
keywords.addElement( "boolean");
keywords.addElement( "break");
keywords.addElement( "byte");
keywords.addElement( "byvalue");
keywords.addElement( "case");
keywords.addElement( "cast");
keywords.addElement( "catch");
keywords.addElement( "char");
keywords.addElement( "class");
keywords.addElement( "const");
keywords.addElement( "continue");
keywords.addElement( "default");
keywords.addElement( "do");
keywords.addElement( "double");
keywords.addElement( "else");
keywords.addElement( "extends");
keywords.addElement( "false");
keywords.addElement( "final");
keywords.addElement( "finally");
keywords.addElement( "float");
keywords.addElement( "for");
keywords.addElement( "future");
keywords.addElement( "generic");
keywords.addElement( "goto");
keywords.addElement( "if");
keywords.addElement( "implements");
keywords.addElement( "import");
keywords.addElement( "inner");
keywords.addElement( "instanceof");
keywords.addElement( "int");
keywords.addElement( "interface");
keywords.addElement( "long");
keywords.addElement( "native");
keywords.addElement( "new");
keywords.addElement( "null");
keywords.addElement( "operator");
keywords.addElement( "outer");
keywords.addElement( "package");
keywords.addElement( "private");
keywords.addElement( "protected");
keywords.addElement( "public");
keywords.addElement( "rest");
keywords.addElement( "return");
keywords.addElement( "short");
keywords.addElement( "static");
keywords.addElement( "super");
keywords.addElement( "switch");
keywords.addElement( "synchronized");
keywords.addElement( "this");
keywords.addElement( "throw");
keywords.addElement( "throws");
keywords.addElement( "transient");
keywords.addElement( "true");
keywords.addElement( "try");
keywords.addElement( "var");
keywords.addElement( "void");
keywords.addElement( "volatile");
keywords.addElement( "while");
}Hope it helped -
Help with a simple 1811 configuration
I have a very basic level of understanding with Cisco products and I need help with what should be simple and even doable by me.
I have a Cisco 1811 integrated router and am simply trying to use it on my home network. I can configure the router with an enable secret password, password encryption, VTY, aux, and cons logins with no issues. The router has 2 Ethernet interfaces, 0 and 1 and 8 switch ports.
The idea is to bring Comcast ISP service into one of the Ethernet ports and then have three machines on the switch ports able to access the Internet. Also I have an off-the shelf wireless router that I thought I would just plug that into an available switch port and allow a wireless AP as well.
This is so simply, that I can't believe I can't figure it out, but I can't.
I set int F1 to DHCP, performed a 'no shut', and connected the ISP's router and have an up and up indication. I have setup a static network with my three machines on the switch ports and enabled all applicable ports and have up and up indications - however, no traffic flow, even amongst my static Layer 2 switched LAN - not even a 'ping'. By my understanding of Layer 2, this should work right now, whether the ISP service is working or not - WHAT AM I DOING WRONG?
The addressing scheme I have ended up on is 172.16.1.0/28
Obviously without the first hurdle cleared, of why the switched LAN doesn’t work, I haven't got any deeper. Do I need to configure NAT? I don't think I would need to in the scenario right?
All of my experience, and none at the CCNA level, has been with larger Cisco equipment. One thing I noticed on the 1811 was that when trying to create a new VLAN, it appears to work yet does not do anything and the 'sh vlans' output returns nothing, not even the VLAN1 I can see with 'sh ip int brief".
Anyway, if anyone has time to help a newbie out I would appreciate it; I’m lost.
Thanks,
JoshThanks for the help Andrew! You know, I think if this was two separate devices (switch and router) I think I would be up and running, but this integrated stuff is throwing me off, not to mention that the IOS is a much older version (I guess) than what I'm used to.
They were throwing this 1811 in the trash can at work, so I just emptied the trash can. I have no documentation at all but I have since found the 1800 series documentation on Cisco.com and have tried to implement the basic configurations cited; with what seems like success, but still no joy. I did have to recover the password and did so with 0x2142, I bypassed the setup and compared the default configuration with what is listed in the documentation and they DO NOT match; I also tried to go through setup mode with the same indications. Additionally I've also learned that the 1800 series is pre-configured on certain options (DHCP, VLAN), which is new to me - I thought Cisco routers were not configured by default - isn't that kind of the point? (By the way, the below port status may not be correct since I now have all the ports unplugged)
Anyway, here is the 'show run' command, the 'sh ip int brief' command, followed by the 'sh version' command:
Show Run
Casino#sh run
Building configuration...
Current configuration : 2006 bytes
version 12.4
service timestamps debug datetime msec
service timestamps log datetime msec
service password-encryption
hostname Casino
boot-start-marker
boot-end-marker
enable secret 5 $1$meWw$nsMTp6US7axi/uE0MWULK.
enable password 7 06535E741C1B584C55
no aaa new-model
ip cef
no ip dhcp use vrf connected
ip dhcp excluded-address 172.16.1.1
ip dhcp pool Casino
import all
network 172.16.1.0 255.255.255.240
default-router 67.165.208.1
dns-server 68.87.89.150
domain-name hsd1.co.comcast.net
no ip domain lookup
ip domain name GinRummy.localhost
ip name-server 68.87.85.102
ip name-server 68.87.69.150
ip auth-proxy max-nodata-conns 3
ip admission max-nodata-conns 3
multilink bundle-name authenticated
archive
log config
hidekeys
interface Loopback0
ip address 172.16.1.1 255.255.255.240
interface FastEthernet0
no ip address
shutdown
duplex auto
speed auto
interface FastEthernet1
ip address dhcp
ip nat outside
ip virtual-reassembly
duplex auto
speed auto
pppoe enable
pppoe-client dial-pool-number 1
interface BRI0
no ip address
encapsulation hdlc
shutdown
interface FastEthernet2
interface FastEthernet3
interface FastEthernet4
interface FastEthernet5
interface FastEthernet6
interface FastEthernet7
interface FastEthernet8
interface FastEthernet9
interface Vlan1
no ip address
ip nat inside
ip virtual-reassembly
interface Dialer0
ip address negotiated
ip mtu 1492
encapsulation ppp
dialer pool 1
ppp authentication chap
ip forward-protocol nd
no ip http server
no ip http secure-server
ip nat pool Casino 172.16.1.2 172.16.1.14 netmask 255.255.255.240
ip nat inside source list 1 interface Dialer0 overload
access-list 1 permit 172.16.1.0 0.0.0.15
dialer-list 1 protocol ip permit
control-plane
line con 0
password 7 080E5916584B4442435E5C
login
line aux 0
password 7 013C135C0A59475A70191E
login
line vty 0 4
password 7 09635B51485756475A5954
login
end
Show IP Interface Brief
Casino#sh ip int brief
Interface IP-Address OK? Method Status Prl
FastEthernet0 unassigned YES NVRAM administratively down do
FastEthernet1 unassigned YES DHCP up do
BRI0 unassigned YES NVRAM administratively down do
BRI0:1 unassigned YES unset administratively down do
BRI0:2 unassigned YES unset administratively down do
FastEthernet2 unassigned YES unset up do
FastEthernet3 unassigned YES unset up do
FastEthernet4 unassigned YES unset up do
FastEthernet5 unassigned YES unset up do
FastEthernet6 unassigned YES unset up do
FastEthernet7 unassigned YES unset up do
FastEthernet8 unassigned YES unset up do
FastEthernet9 unassigned YES unset up up
Vlan1 unassigned YES NVRAM up up
Loopback0 172.16.1.1 YES manual up up
Dialer0 unassigned YES manual up up
NVI0
'show version'
Casino#sh ver
Cisco IOS Software, C181X Software (C181X-ADVIPSERVICESK9-M), Version 12.4(15))
Technical Support: http://www.cisco.com/techsupport
Copyright (c) 1986-2008 by Cisco Systems, Inc.
Compiled Thu 24-Jan-08 13:05 by prod_rel_team
ROM: System Bootstrap, Version 12.3(8r)YH12, RELEASE SOFTWARE (fc1)
Casino uptime is 52 minutes
System returned to ROM by reload at 17:09:25 UTC Fri Jul 1 2011
System image file is "flash:c181x-advipservicesk9-mz.124-15.T3.bin"
This product contains cryptographic features and is subject to United
States and local country laws governing import, export, transfer and
use. Delivery of Cisco cryptographic products does not imply
third-party authority to import, export, distribute or use encryption.
Importers, exporters, distributors and users are responsible for
compliance with U.S. and local country laws. By using this product you
agree to comply with applicable laws and regulations. If you are unable
to comply with U.S. and local laws, return this product immediately.
A summary of U.S. laws governing Cisco cryptographic products may be found at:
http://www.cisco.com/wwl/export/crypto/tool/stqrg.html
If you require further assistance please contact us by sending email to
[email protected].
Cisco 1812 (MPC8500) processor (revision 0x400) with 118784K/12288K bytes of m.
Processor board ID FHK120622J3, with hardware revision 0000
10 FastEthernet interfaces
1 ISDN Basic Rate interface
31488K bytes of ATA CompactFlash (Read/Write)
Configuration register is 0x2102
Thanks again for your help,
Josh -
Hello
I am very new to Java and am currently studying a course in the language.
I am working through a tutorial at the moment and a question has been asked and I am struggling a bit
I have been given the code to a program that creates a window with a ball bouncing around inside the window.
There are 2 classes (code below) - Call class - this contains all the code need to create the ball and BallWorld Class (the main Class) this create the window and moves the ball, it also detects if the ball hits the edge of the window, whne this happens it redirects the ball. I understand how all this code works
I have been asked the following:-
Rather than testing whether or not the ball has hit the wall in the nmain program, we could use inhertitance to provide a specialized forom of Ball. Create a class BoundedBall that inherits from the class Ball. The constructor for this class should provide the height and width of the window, which should be maintained as data fields in the class, rewrite the move method so that the ball moves outside the bound, it automatically reflects its direction. Finally rewrite the BallWorld class to use an instance of BoundedBall rather than ordianary Ball, and elimiante the bounds test in the main program.
I am having trouble with this and I can not get my code to work, I think I may be going in completly the wrong direction with the code can sombody please provide me with a simple working code for both the BoundedBall and ammended BallWorld class, as this will help me understand whare I am going wrong
Ball class
//a generic round colored object that moves
import java.awt.*;
public class Ball {
public Ball (Point lc, int r) { //constructor for new ball
//ball centre at point loc, radius rad
loc = lc;
rad = r;
protected Point loc; //position in window
protected int rad; //radius of ball
protected double changeInX = 0.0; //horizontal change in ball position in one cycle
protected double changeInY = 0.0; //vertical change in ball position in one cycle
protected Color color = Color.blue; //colour of ball
//methods that set attributes of ball
public void setColor(Color newColor) {color = newColor;}
public void setMotion(double dx,double dy)
{changeInX = dx; changeInY = dy;}
//methods that access attributes of ball
public int radius() {return rad;}
public Point location() {return loc;}
//methods to reverse motion of the ball
public void reflectVert(){ changeInY = -changeInY; }
public void reflectHorz(){ changeInX = -changeInX; }
//methods to move the ball
public void moveTo(int x, int y) {loc.move(x,y);}
public void move(){loc.translate((int)changeInX, (int)changeInY);}
//method to display ball
public void paint (Graphics g) {
g.setColor(color);
g.fillOval(loc.x-rad, loc.y-rad, 2*rad, 2*rad);
BallWorld class
//A bouncing ball animation
import java.awt.*; //import the awt package
import javax.swing.JFrame; //import the JFrame class from the swing package
public class BallWorld extends JFrame{
public static void main (String [] args){
BallWorld world = new BallWorld(Color.red);
world.show();
for(int i = 0; i < 1000; i++) world.run();
System.exit(0);
public static final int FrameWidth = 600;
public static final int FrameHeight = 400;
private Ball aBall = new Ball(new Point (50,50),20);
private BallWorld(Color ballColor) { //constructor for new window
//resize frame, initialize title
setSize(FrameWidth, FrameHeight);
setTitle("Ball World");
//set colour and motion of ball
aBall.setColor(ballColor);
aBall.setMotion(3.0, 6.0);
public void paint (Graphics g) {
//first draw the ball
super.paint(g);
aBall.paint(g);
public void run(){
//move ball slightly
aBall.move();
Point pos =aBall.location();
if ((pos.x < aBall.radius()) ||
(pos.x > FrameWidth - aBall.radius()))
aBall.reflectHorz();
if ((pos.y < aBall.radius()) ||
(pos.y > FrameHeight - aBall.radius()))
aBall.reflectVert();
repaint();
try{
Thread.sleep(50);
} catch(InterruptedException e) {System.exit(0);}Here - you can study this :0))import java.awt.*;
import javax.swing.*;
public class MovingBall extends JFrame {
mapPanel map = new mapPanel();
public MovingBall() {
setBounds(10,10,400,300);
setContentPane(map);
public class mapPanel extends JPanel {
Ball ball = new Ball(this);
public void paintComponent(Graphics g) {
super.paintComponent(g);
ball.paint(g);
public class Ball extends Thread {
mapPanel map;
int x = 200, y = 20, xi = 1, yi = 1;
public Ball(mapPanel m) {
map = m;
start();
public synchronized void run(){
while (true) {
try{
sleep(10);
catch(InterruptedException i){
System.out.print("Interrupted: ");
move();
public void move() {
map.repaint(x-1,y-1,22,22);
if (x > map.getWidth()-20 || x < 0) xi = xi*-1;
if (y > map.getHeight()-20 || y < 0) yi = yi*-1;
x = x + xi;
y = y + yi;
map.repaint(x-1,y-1,22,22);
public void paint(Graphics g) {
Graphics2D g2 = (Graphics2D)g;
g2.setColor(Color.red);
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
g2.fillOval(x,y,20,20);
g2.dispose();
public static void main(String[] args) {
new MovingBall().show();
}
Maybe you are looking for
-
Many of my albums are listed in iTMS but match is uploading my local music
I've been an Apple user for over 15 years but for all its simplicity Match more or less stumps me so I am coming here hoping one less muddled can explain this. I have a library of 21,000 and after its initial trawl iTunes Match seemed to indicate it
-
How can I install epson stylus nx625 driver on my Macbook Pro?
I've spent a frustrating few hours today going back and forth between Apple tech support and Epson tech support and still do not have a solution to what should be a simple problem. I got a new MacBook Pro as a work computer and want to install my ho
-
Why is there no info in my Style Panels in InDesign CS4?
Adobe CS4 on the Mac (OS 10.6.6) There is NO INFORMATION at all in my Paragraph and Character Styles panels. No icons, no styles, no little garbage can, no default styles. Cannot load any styles. When I use the arrows at the right of the panel to cre
-
Regarding VAT Registration No. In Customer
Hi Everybody My issue is I have created one customer master and i maintained VAT reg.no in Control data and i have saved. But after some time I have removed that VAT reg.no in the Customer Master. After that I created Quotation Document here System i
-
Email adress bull crap!!!!!
so my buddy sent me his email adress but spelt it wrong and i ended up saving it and erased it then saved his correct email adress. well when im sending an email and type in his name all of the incorrect email adresses that i DELEATED are still shown